Asd*_*dfg 2 powershell windows-server-2016 windows-server-2019
$AllDrivesExceptBootDrive = Get-Volume | Where-Object {$_.DriveLetter -ne 'C'} | Select-Object DriveLetter, AllocationUnitSize
foreach ($d in $AllDrivesExceptBootDrive)
{
Write-Host "Checking Drive $d.DriveLetter"
}
Run Code Online (Sandbox Code Playgroud)
印刷:
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
Run Code Online (Sandbox Code Playgroud)
如何保留引号Write-Host并仍按如下方式打印?
Checking Drive F
Checking Drive G
Checking Drive E
Checking Drive H
Checking Drive I
Run Code Online (Sandbox Code Playgroud)
只有简单的变量引用可以直接嵌入可扩展字符串中。使用数组索引或成员访问的变量引用必须包含在子表达式中。
更改字符串文字以使用子表达式运算符包围表达式$(),如下所示:
Write-Host "Checking Drive $($d.DriveLetter)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1758 次 |
| 最近记录: |