azure - 我正在尝试在 azure cloud 的 powershell 脚本中添加异常处理,但是当错误发生时尝试块没有响应
问题描述
#adding wrong parameters for checking the try block
$RGName = "RG1"
$VMName="VM1"
$VMSize="standard_B1ls"
$VirtualMachine = Get-AzVm | Where-Object {$_.ResourceGroupName -eq $RGName } | Where-Object {$_.Name -eq $VMName}
$virtualMachine.HardwareProfile.VmSize = $VMSize
#try block
try{
Update-AzVM -VM $VirtualMachine -ResourceGroupName $RGname
write-host "you are in try block "
}
catch{
write-host "you are in catch block "
}
catch 块不起作用我不需要打印 try 块 write-host 发生异常而不是 print catch write-host
解决方案
推荐阅读
- google-apps-script - 如何处理 myDrive 文件的 Access-Control-Allow-Origin
- python - 根据 Python Regex 中的条件拆分字符列表
- laravel-5.2 - 更新表的多个列
- r - 将数据框分成两部分(wrt NA)并绘制一个关于每个部分的条件图
- xaml - ActivityIndicator 的可重用 ContentView 绑定
- nvm - 如何解决 /c/Program Files/nodejs/node: line 1: syntax error near unexpected token `newline' 错误?
- vim - VimScript 执行搜索不再起作用
- r - 从 travis-ci 上的 github repo 的特定分支安装特定的 R 包
- javascript - 如何更改 Chrome 扩展内部 HTML 页面
- android - 未通过调用 LinkedIn API Oauth 2.0 版获取公共个人资料 URL