$AllDrivesExceptBootDrive = Get-Volume | Where-Object {$_.DriveLetter -ne 'C'} | Select-Object DriveLetter, AllocationUnitSize
foreach ($d in $AllDrivesExceptBootDrive)
{
Write-Host "Checking Drive $d.DriveLetter"
}
印刷:
Checking Drive @{DriveLetter=F; AllocationUnitSize=4096}.DriveLetter
Checking Drive @{DriveLetter=G; AllocationUnitSize=4096}.DriveLetter
Checking Drive @{DriveLetter=E; AllocationUnitSize=4096}.DriveLetter
Checking Drive @{DriveLetter=H; AllocationUnitSize=4096}.DriveLetter
Checking Drive @{DriveLetter=I; AllocationUnitSize=4096}.DriveLetter
我如何保留引號Write-Host并仍然列印如下?
Checking Drive F
Checking Drive G
Checking Drive E
Checking Drive H
Checking Drive I
uj5u.com熱心網友回復:
從該about_Quoting_Rules幫助主題:
只有簡單的變數參考可以直接嵌入到可擴展字串中。使用陣列索引或成員訪問的變數參考必須包含在子運算式中。
更改字串文字以使用子運算式 operator 包圍運算式$(),如下所示:
Write-Host "Checking Drive $($d.DriveLetter)"
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/379969.html
標籤:电源外壳 windows-server-2016 windows-server-2019
上一篇:PowerShell-服務器本地管理員從服務器串列報告
下一篇:如何指示組合框已填充選擇?
