azure-powershell-1/tools/AzureRM.Example.psm1

150 строки
5.2 KiB
PowerShell
Исходник Обычный вид История

#
# 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
2018-11-13 02:44:39 +03:00
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 })))
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."
}
}
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'))
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
}
Merge release-2020-04-21 (#11620) * Update changelog (#11573) * Adding support for ForceFirewallPolicy association on Application Gateway * updates ? * CredScan suppression * Publishing release version of Maintenance cmdlets for GA (#11574) Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com> * DPDTimeout core commits * help files * changelog * add change log for azs release (#11594) * Remove netcoreapp2.1 from test target (#11593) * Remove netcoreapp2.1 from test target * Make Maintenance to 1.0.0 GA (#11578) * update version to 1.0.0 * Remove netcoreapp2.1 from test target (#11593) * Remove netcoreapp2.1 from test target Co-authored-by: wyunchi-ms <wang935863431@126.com> Co-authored-by: Dingmeng Xue <56333063+dingmeng-xue@users.noreply.github.com> * Check PS Version when importing Az.Storage which using Azure.Core (#11576) * azure api management breaking change notifications (#11602) * azure api management breaking change notifications * notification param fixed Co-authored-by: vfedonkin <vifedo@microsoft.com> * release-2020-04-21 (#11619) Co-authored-by: Venkata Krishnan Anantha Raman <vekrishn@microsoft.com> Co-authored-by: Anton Evseev <v-anevse@microsoft.com> Co-authored-by: gautamd-ms <59714872+gautamd-ms@users.noreply.github.com> Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com> Co-authored-by: Henry Chen <henche@microsoft.com> Co-authored-by: erich-wang <eriwan@microsoft.com> Co-authored-by: wyunchi-ms <wang935863431@126.com> Co-authored-by: Vitaliy Fedonkin <vitaliy.fedonkin@gmail.com> Co-authored-by: vfedonkin <vifedo@microsoft.com>
2020-04-17 13:01:45 +03:00
%AZURECOREPREREQUISITE%
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
if (Get-Module %AZORAZURERM%.profile -ErrorAction Ignore)
2018-11-03 00:17:29 +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")
Preload-Assembly -AssemblyDirectory $preloadPath
$preloadPath = (Join-Path $PSScriptRoot -ChildPath "ModuleAlcAssemblies")
Preload-Assembly -AssemblyDirectory $preloadPath
2018-09-12 07:01:35 +03:00
$netCorePath = (Join-Path $PSScriptRoot -ChildPath "NetCoreAssemblies")
if($PSEdition -eq 'Core' -and (Test-Path $netCorePath -ErrorAction Ignore))
{
try
{
$loadedAssemblies = ([System.AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {New-Object -TypeName System.Reflection.AssemblyName -ArgumentList $_.FullName} )
Get-ChildItem -ErrorAction Stop -Path $netCorePath -Filter "*.dll" | ForEach-Object {
$assemblyName = ([System.Reflection.AssemblyName]::GetAssemblyName($_.FullName))
$matches = ($loadedAssemblies | Where-Object {$_.Name -eq $assemblyName.Name})
if (-not $matches)
{
try
{
Add-Type -Path $_.FullName -ErrorAction Ignore | Out-Null
}
catch {
Merge release-2020-04-21 (#11620) * Update changelog (#11573) * Adding support for ForceFirewallPolicy association on Application Gateway * updates ? * CredScan suppression * Publishing release version of Maintenance cmdlets for GA (#11574) Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com> * DPDTimeout core commits * help files * changelog * add change log for azs release (#11594) * Remove netcoreapp2.1 from test target (#11593) * Remove netcoreapp2.1 from test target * Make Maintenance to 1.0.0 GA (#11578) * update version to 1.0.0 * Remove netcoreapp2.1 from test target (#11593) * Remove netcoreapp2.1 from test target Co-authored-by: wyunchi-ms <wang935863431@126.com> Co-authored-by: Dingmeng Xue <56333063+dingmeng-xue@users.noreply.github.com> * Check PS Version when importing Az.Storage which using Azure.Core (#11576) * azure api management breaking change notifications (#11602) * azure api management breaking change notifications * notification param fixed Co-authored-by: vfedonkin <vifedo@microsoft.com> * release-2020-04-21 (#11619) Co-authored-by: Venkata Krishnan Anantha Raman <vekrishn@microsoft.com> Co-authored-by: Anton Evseev <v-anevse@microsoft.com> Co-authored-by: gautamd-ms <59714872+gautamd-ms@users.noreply.github.com> Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com> Co-authored-by: Henry Chen <henche@microsoft.com> Co-authored-by: erich-wang <eriwan@microsoft.com> Co-authored-by: wyunchi-ms <wang935863431@126.com> Co-authored-by: Vitaliy Fedonkin <vitaliy.fedonkin@gmail.com> Co-authored-by: vfedonkin <vifedo@microsoft.com>
2020-04-17 13:01:45 +03:00
Write-Verbose $_
}
}
}
}
catch {}
}
2017-11-14 10:59:11 +03:00
%IMPORTED-DEPENDENCIES%
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-08-09 03:11:12 +03:00
})
}
2018-03-15 01:17:10 +03:00
}
2018-11-13 08:26:35 +03:00
}