你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Add-AzVmssExtension

将扩展添加到 VMSS。

语法

Default (默认值)

Add-AzVmssExtension
    [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
    [[-Name] <String>]
    [[-Publisher] <String>]
    [[-Type] <String>]
    [[-TypeHandlerVersion] <String>]
    [[-AutoUpgradeMinorVersion] <Boolean>]
    [[-Setting] <Object>]
    [[-ProtectedSetting] <Object>]
    [-EnableAutomaticUpgrade <Boolean>]
    [-ForceUpdateTag <String>]
    [-ProvisionAfterExtension <String[]>]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

说明

Add-AzVmssExtension cmdlet 将扩展添加到虚拟机规模集(VMSS)。

示例

示例 1:向 VMSS 添加扩展

Add-AzVmssExtension -VirtualMachineScaleSet $VMSS -Name $ExtName -Publisher $Publisher -Type $ExtType -TypeHandlerVersion $ExtVer -AutoUpgradeMinorVersion $True

此命令将扩展添加到 VMSS。

示例 2:使用设置和受保护的设置将扩展添加到 VMSS

$Settings = @{"fileUris" = "[]"; "commandToExecute" = ""};
$ProtectedSettings = @{"storageAccountName" = $stoname; "storageAccountKey" = $stokey};

Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name $vmssExtensionName -Publisher $vmssPublisher  `
  -Type $vmssExtensionType -TypeHandlerVersion $ExtVer -AutoUpgradeMinorVersion $True  `
  -Setting $Settings -ProtectedSetting $ProtectedSettings

示例 3:使用设置和受保护的设置将扩展添加到 VMSS

$BatchFile = "runbook.sh"
$ResourceGroupName = "HelloRG"
$VMScaleSetName = "HelloVmSS"
$TypeHandlerVersion = 2.1

#Best Practice for secured parameters.
$protectedSettings = @{
"managedIdentity" = @{ "clientId" = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"};
}

$publicSettings = @{
"fileUris"= (,"https://storage.blob.core.windows.net/itfiles/$($BatchFile)");
"commandToExecute"= "sh $($BatchFile)"
}

# Get information about the scale set
$vmss = Get-AzVmss `
            -ResourceGroupName $ResourceGroupName `
            -VMScaleSetName $VMScaleSetName

Add-AzVmssExtension -VirtualMachineScaleSet $vmss `
    -Name "CustomScript" `
    -Publisher "Microsoft.Azure.Extensions" `
    -Type "CustomScript" `
    -TypeHandlerVersion $TypeHandlerVersion `
    -AutoUpgradeMinorVersion $true `
    -Setting $publicSettings `
    -ProtectedSetting $protectedSettings

Update-AzVmss `
    -ResourceGroupName $ResourceGroupName `
    -Name $VMScaleSetName `
    -VirtualMachineScaleSet $vmss

此命令在 Blob 存储上使用示例 bash 脚本将扩展添加到 VMSS,在受保护设置中指定 Blob 存储和可执行命令的 URL 以及安全访问。

参数

-AutoUpgradeMinorVersion

指示扩展版本是否应自动更新到较新的次要版本。

参数属性

类型:

Nullable<T>[Boolean]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:5
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Confirm

在运行 cmdlet 之前,提示你进行确认。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-DefaultProfile

用于与 Azure 通信的凭据、帐户、租户和订阅。

参数属性

类型:IAzureContextContainer
默认值:None
支持通配符:False
不显示:False
别名:AzContext, AzureRmContext, AzureCredential

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-EnableAutomaticUpgrade

指示如果有较新版本的扩展可用,平台是否应自动升级扩展。

参数属性

类型:

Nullable<T>[Boolean]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ForceUpdateTag

如果提供值并且与上一个值不同,则即使扩展配置未更改,扩展处理程序也会强制更新。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Name

指定此 cmdlet 添加的扩展的名称。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:1
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ProtectedSetting

将扩展的专用配置指定为字符串。 此 cmdlet 加密专用配置。

参数属性

类型:Object
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:7
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ProvisionAfterExtension

需要预配此扩展的扩展名称的集合。

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Publisher

指定扩展发布者的名称。 发布者在注册扩展时提供名称。 这可以使用 Get-AzVMImagePublisher cmdlet 获取发布者。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:2
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Setting

将公共配置指定为扩展的字符串。 此 cmdlet 不加密公共配置。

参数属性

类型:Object
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:6
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Type

指定扩展类型。 可以使用 Get-AzVMExtensionImageType cmdlet 获取扩展类型。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:3
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-TypeHandlerVersion

指定要用于此虚拟机的扩展版本。 可以使用 Get-AzVMExtensionImage cmdlet 获取扩展的版本。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:4
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-VirtualMachineScaleSet

指定 VMSS 对象。 可以使用 New-AzVmssConfig 创建对象。

参数属性

类型:PSVirtualMachineScaleSet
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:0
必需:True
来自管道的值:True
来自管道的值(按属性名称):True
来自剩余参数的值:False

-WhatIf

显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:无线

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

PSVirtualMachineScaleSet

String

Nullable<T>

Object

输出

PSVirtualMachineScaleSet