从 PowerShell 中删除 OpenStack 实例

Deleting an OpenStack instance from PowerShell

我已经编写了一个 PowerShell 脚本,它将从一个 txt 文件中获取 InstanceID。它们的格式为 c5d1fa69-fe2d-4a5b-8446-5c9751429e48.

我试图删除使用此 ID 的实例,但无法正常工作。

如果我将 $ID 更改为 "c5d1fa69-fe2d-4a5b-8446-5c9751429e48",它会正常工作。

$instancesID = Get-Content C:\instance.txt

foreach ($entry in $instancesID) {
    #Get rid of the white space from txt file
    $ID = $entry.Trim()
}
nova delete $ID

如何从文本文件中获取 ID,以便它执行如下命令:

nova delete c5d1fa69-fe2d-4a5b-8446-5c9751429e48

正如 指出的那样,您很可能只需要将 nova 命令行放在循环中:

foreach ($entry in $instancesID) {
    $ID = $entry.Trim()
    nova delete $ID
}