小编NW_*_*_92的帖子

ForEach 循环未完成列表

所以我有一个主机名数组,我想在 45 主机上运行命令“Shutdown-VMGuest”。我想一次关闭 20 次,但是当我完成 40 次时却错过了最后 5 次。这是下面的代码,有人知道我做错了什么吗?

    [System.Collections.ArrayList]$currentStartList = @()

    $i=0
    foreach ($vmHost in $PowerOffList){
        $i++
        [void]$currentstartList.Add($vmHost)
        if ($i -gt "19"){
            $vmToPowerOff = Get-VM -Name $currentstartList
            $Confirmation= Read-Host "`n Do you want to hard powerdown the following VMs (y/n)? $currentstartList"
            if ($Confirmation -eq 'y'){
                Write-Output "`n Trying to power down VMs safely: $vmToPowerOff"
                try {
                    Shutdown-VMGuest $vmToPowerOff
                }
                catch {
                    Write-Output "`n $vmToPowerOff has failed to power off safely"
                    $FailedVMs.Add($vmToPowerOff)
                }

                #clear lists
                [System.Collections.ArrayList]$currentstartList = @()
                $i=0
                sleep …
Run Code Online (Sandbox Code Playgroud)

powershell foreach

4
推荐指数
1
解决办法
45
查看次数

使用 Python 将 Excel 转换为 JSON

我有一个excel文件,我想把它转换成一个JSON文件。所以excel是这样的:

-------------------------
| Col A | Col C | Col F |
--------+-------+--------
|   1   |   A   |   EE  |
|   2   |   B   |   FF  |
|   4   |   C   |   FF  |
|   5   |   D   |   HH  |
|   6   |   D   |   HH  |
|   7   |   A   |   EE  |
|   8   |   E   |   EE  |
--------------------------
Run Code Online (Sandbox Code Playgroud)

我希望JSON遵循以下格式:

{
"EE": {
    "A": {
      "Col A key": "1",
      "Col A key": …
Run Code Online (Sandbox Code Playgroud)

python excel json python-3.x

2
推荐指数
3
解决办法
2万
查看次数

标签 统计

excel ×1

foreach ×1

json ×1

powershell ×1

python ×1

python-3.x ×1