2018-10-09 02:20:43 +03:00
#
# Script module for module '%MODULE-NAME%' that is executed when '%MODULE-NAME%' is imported in a PowerShell session.
#
# Generated by: Microsoft Corporation
#
2017-11-02 21:00:57 +03:00
# Generated on: %DATE%
2018-10-09 02:20:43 +03:00
#
2017-11-02 21:00:57 +03:00
$PSDefaultParameterValues . Clear ( )
Set-StrictMode -Version Latest
2018-11-13 02:44:39 +03:00
function Test-DotNet
{
try
{
2019-10-11 05:57:45 +03:00
if ( ( Get-PSDrive 'HKLM' -ErrorAction Ignore ) -and ( -not ( Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' -ErrorAction Stop | Get-ItemPropertyValue -ErrorAction Stop -Name Release | Where-Object { $_ -ge 461808 } ) ) )
2018-11-13 02:44:39 +03:00
{
throw " .NET Framework versions lower than 4.7.2 are not supported in Az. Please upgrade to .NET Framework 4.7.2 or higher. "
}
}
2018-11-13 22:46:09 +03:00
catch [ System.Management.Automation.DriveNotFoundException ]
2018-11-13 02:44:39 +03:00
{
Write-Verbose " .NET Framework version check failed. "
}
}
2021-09-20 16:50:33 +03:00
function Preload-Assembly {
param (
[ string ]
$AssemblyDirectory
)
if ( $PSEdition -eq 'Desktop' -and ( Test-Path $AssemblyDirectory -ErrorAction Ignore ) )
{
try
{
Get-ChildItem -ErrorAction Stop -Path $AssemblyDirectory -Filter " *.dll " | ForEach-Object {
try
{
Add-Type -Path $_ . FullName -ErrorAction Ignore | Out-Null
}
catch {
Write-Verbose $_
}
}
}
catch { }
}
}
2018-11-30 20:17:29 +03:00
if ( % ISAZMODULE % -and ( $PSEdition -eq 'Desktop' ) )
2018-11-09 04:21:24 +03:00
{
2018-11-10 01:33:22 +03:00
if ( $PSVersionTable . PSVersion -lt [ Version ] '5.1' )
2018-11-09 04:21:24 +03:00
{
throw " PowerShell versions lower than 5.1 are not supported in Az. Please upgrade to PowerShell 5.1 or higher. "
}
2018-11-12 22:57:48 +03:00
Test-DotNet
2018-11-09 04:21:24 +03:00
}
2020-04-17 13:01:45 +03:00
% AZURECOREPREREQUISITE %
2018-11-30 20:17:29 +03:00
if ( Test-Path -Path " $PSScriptRoot \StartupScripts " -ErrorAction Ignore )
2018-11-01 01:01:25 +03:00
{
2018-11-13 22:46:09 +03:00
Get-ChildItem " $PSScriptRoot \StartupScripts " -ErrorAction Stop | ForEach-Object {
. $_ . FullName
2018-11-01 01:01:25 +03:00
}
}
2018-11-03 00:17:29 +03:00
2018-11-30 20:17:29 +03:00
if ( Get-Module % AZORAZURERM % . profile -ErrorAction Ignore )
2018-11-03 00:17:29 +03:00
{
2018-12-13 12:31:55 +03:00
Write-Warning ( " %AZORAZURERM%.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. " +
" If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide. " )
throw ( " %AZORAZURERM%.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. " +
" If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide. " )
2018-11-08 03:58:28 +03:00
}
2018-09-12 07:01:35 +03:00
$preloadPath = ( Join-Path $PSScriptRoot -ChildPath " PreloadAssemblies " )
2021-09-20 16:50:33 +03:00
Preload-Assembly -AssemblyDirectory $preloadPath
$preloadPath = ( Join-Path $PSScriptRoot -ChildPath " ModuleAlcAssemblies " )
Preload-Assembly -AssemblyDirectory $preloadPath
2018-09-12 07:01:35 +03:00
2018-09-19 05:52:11 +03:00
$netCorePath = ( Join-Path $PSScriptRoot -ChildPath " NetCoreAssemblies " )
2018-11-30 20:17:29 +03:00
if ( $PSEdition -eq 'Core' -and ( Test-Path $netCorePath -ErrorAction Ignore ) )
2018-09-19 05:52:11 +03:00
{
2018-10-09 02:20:43 +03:00
try
2018-09-19 05:52:11 +03:00
{
2019-10-11 05:57:45 +03:00
$loadedAssemblies = ( [ System.AppDomain ] :: CurrentDomain . GetAssemblies ( ) | ForEach-Object { New-Object -TypeName System . Reflection . AssemblyName -ArgumentList $_ . FullName } )
2018-11-30 20:17:29 +03:00
Get-ChildItem -ErrorAction Stop -Path $netCorePath -Filter " *.dll " | ForEach-Object {
2018-09-19 05:52:11 +03:00
$assemblyName = ( [ System.Reflection.AssemblyName ] :: GetAssemblyName ( $_ . FullName ) )
$matches = ( $loadedAssemblies | Where-Object { $_ . Name -eq $assemblyName . Name } )
if ( -not $matches )
{
2020-04-14 02:08:09 +03:00
try
{
Add-Type -Path $_ . FullName -ErrorAction Ignore | Out-Null
}
catch {
2020-04-17 13:01:45 +03:00
Write-Verbose $_
2020-04-14 02:08:09 +03:00
}
2018-09-19 05:52:11 +03:00
}
}
}
catch { }
}
2017-11-14 10:59:11 +03:00
% IMPORTED-DEPENDENCIES %
2019-01-14 22:16:14 +03:00
if ( Test-Path -Path " $PSScriptRoot \PostImportScripts " -ErrorAction Ignore )
{
Get-ChildItem " $PSScriptRoot \PostImportScripts " -ErrorAction Stop | ForEach-Object {
. $_ . FullName
}
}
2017-11-15 20:42:08 +03:00
$FilteredCommands = % DEFAULTRGCOMMANDS %
2017-11-03 21:23:29 +03:00
2018-03-20 03:11:01 +03:00
if ( $Env:ACC_CLOUD -eq $null )
2018-03-15 01:17:10 +03:00
{
$FilteredCommands | ForEach-Object {
2018-09-21 23:31:13 +03:00
$existingDefault = $false
foreach ( $key in $global:PSDefaultParameterValues . Keys )
{
if ( $_ -like " $key " )
{
$existingDefault = $true
}
}
if ( ! $existingDefault )
2018-08-09 03:11:12 +03:00
{
$global:PSDefaultParameterValues . Add ( $_ ,
{
2018-09-06 21:07:54 +03:00
if ( ( Get-Command Get-AzContext -ErrorAction Ignore ) -eq $null )
{
$context = Get-AzureRmContext
}
else
{
$context = Get-AzContext
}
2018-08-09 03:11:12 +03:00
if ( ( $context -ne $null ) -and $context . ExtendedProperties . ContainsKey ( " Default Resource Group " ) ) {
$context . ExtendedProperties [ " Default Resource Group " ]
2018-10-09 02:20:43 +03:00
}
2018-08-09 03:11:12 +03:00
} )
}
2018-03-15 01:17:10 +03:00
}
2018-11-13 08:26:35 +03:00
}