-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathAzureRM.Example.psm1
128 lines (111 loc) · 4.35 KB
/
AzureRM.Example.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# Script module for module '%MODULE-NAME%' that is executed when '%MODULE-NAME%' is imported in a PowerShell session.
#
# Generated by: Microsoft Corporation
#
# Generated on: %DATE%
#
$PSDefaultParameterValues.Clear()
Set-StrictMode -Version Latest
function Test-DotNet
{
try
{
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 })))
{
throw ".NET Framework versions lower than 4.7.2 are not supported in Az. Please upgrade to .NET Framework 4.7.2 or higher."
}
}
catch [System.Management.Automation.DriveNotFoundException]
{
Write-Verbose ".NET Framework version check failed."
}
}
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 {}
}
}
if (%ISAZMODULE% -and ($PSEdition -eq 'Desktop'))
{
if ($PSVersionTable.PSVersion -lt [Version]'5.1')
{
throw "PowerShell versions lower than 5.1 are not supported in Az. Please upgrade to PowerShell 5.1 or higher."
}
Test-DotNet
}
%AZURECOREPREREQUISITE%
if (Test-Path -Path "$PSScriptRoot\StartupScripts" -ErrorAction Ignore)
{
Get-ChildItem "$PSScriptRoot\StartupScripts" -ErrorAction Stop | ForEach-Object {
. $_.FullName
}
}
# [windows powershell] preload assemblies
%PRELOAD-ASSEMBLY%
# [windows powershell] preload module alc assemblies
$preloadPath = (Join-Path $PSScriptRoot -ChildPath "ModuleAlcAssemblies")
Preload-Assembly -AssemblyDirectory $preloadPath
if (Get-Module %AZORAZURERM%.profile -ErrorAction Ignore)
{
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.")
}
%IMPORTED-DEPENDENCIES%
if (Test-Path -Path "$PSScriptRoot\PostImportScripts" -ErrorAction Ignore)
{
Get-ChildItem "$PSScriptRoot\PostImportScripts" -ErrorAction Stop | ForEach-Object {
. $_.FullName
}
}
$FilteredCommands = %DEFAULTRGCOMMANDS%
if ($Env:ACC_CLOUD -eq $null)
{
$FilteredCommands | ForEach-Object {
$existingDefault = $false
foreach ($key in $global:PSDefaultParameterValues.Keys)
{
if ($_ -like "$key")
{
$existingDefault = $true
}
}
if (!$existingDefault)
{
$global:PSDefaultParameterValues.Add($_,
{
if ((Get-Command Get-AzContext -ErrorAction Ignore) -eq $null)
{
$context = Get-AzureRmContext
}
else
{
$context = Get-AzContext
}
if (($context -ne $null) -and $context.ExtendedProperties.ContainsKey("Default Resource Group")) {
$context.ExtendedProperties["Default Resource Group"]
}
})
}
}
}
%COMMAND-NOT-FOUND%