powershell - 变量中的 Azure Powershell VM 停止状态
问题描述
我正在尝试编写一个 PowerShell 脚本,该脚本将在我的资源组中查找关闭的虚拟机并取消分配它们。当我尝试将以下脚本分配为变量时,以下脚本的输出没有给我 VM 名称“clean”。最终结果是执行 Stop-AzureRmVM -ResourceGroupName LAB -Name $VM -force
因此,对于更多上下文,假设 AVGJOE-DC1 处于停止状态,我在 Azure Powershell 中运行以下行,它将显示
Name
----
AVGJOE-DC1
如果我尝试使用 $VM 在
Stop-AzureRmVM -ResourceGroupName LAB -Name $VM -force
由于变量被设置为更长的字符串(例如
MicroSoftComputerResource\Resourcegroup[@Name=AVGJOE-DC1]
.
希望这是有道理的。
$VM = Get-AzureRmVM -ResourceGroupName LAB | get-azurermvm -Status | ?{$_.statuses.displaystatus -eq "VM stopped"} | select name
解决方案
推荐阅读
- firebase - 无法从 GCP Cloud Build 部署到 Firebase 托管
- mysql - 尝试在 Ubuntu 18.04 上安装 mysqlclient 时出现一个奇怪的错误
- appinsights - 应用程序洞察跟踪 System.IO.StreamWriter.write 异常处的 System.OverflowException
- c++ - Allegro5 C++:无法加载音频样本
- c++ - 如何优化这个排序代码,这不是在时限内执行。这个问题来自hackerrank
- reactjs - 世博会构建失败 ENOENT
- c# - C# showdialog 窗口有时停留在主窗口的后面
- javascript - 如何设置用户不能在第一个数字中输入数字0?
- c# - 我如何在 untiy 2d 中拖动和启动?
- c++ - set::find() 不适用于用户定义数据类型