小编neo*_*ors的帖子

使用 Powershell 使用 Azure VM 创建自动关机策略

我正在尝试使用 Powershell 为我的 Azure VM 创建自动关闭策略,但一直遇到此错误:

New-AzureRmResource : MissingRequiredProperty :缺少必需的属性 TargetResourceId。在 C:\Users\home\Documents\CreateAzureVM.ps1:167 char:1 + New-AzureRmResource -Location $Loc -ResourceId $ScheduledShutdownReso ... + ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : CloseError: (:) [New-AzureRmResource], ErrorResponseMessageException +fullyQualifiedErrorId : MissingRequiredProperty,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceCmdlet

我对如何解决这个错误一无所知,到目前为止,这是我的脚本:

 $SubscriptionId = $AzContext.Context.Subscription.Id;  
$VMResourceId = (Get-AzureRmVM).id
$ScheduledShutdownResourceId = "/subscriptions/$SubscriptionId/resourceGroups/$RSGName/providers/microsoft.devtestlab/schedules/shutdown-computevm-$VMName"

$Properties = @{}
$Properties.Add('status', 'Enabled')
$Properties.Add('taskType', 'ComputeVmShutdownTask')
$Properties.Add('dailyRecurrence', @{'time'= 1159})
$Properties.Add('timeZoneId', "Eastern Standard Time")
$Properties.Add('notificationSettings', @{status='Disabled'; timeInMinutes=15})
$Properties.Add('targetResourceId', $VMResourceId)

#Error
New-AzureRmResource -Location $Loc -ResourceId $ScheduledShutdownResourceId -Properties $Properties -Force
Run Code Online (Sandbox Code Playgroud)

powershell virtual-machine azure

2
推荐指数
1
解决办法
2271
查看次数

标签 统计

azure ×1

powershell ×1

virtual-machine ×1