我將 get-disk 放入一個變數中,當我想用?? clear-disk 對其進行管道傳輸時,我收到 InputObject is null 錯誤訊息。但是如果我在 Powershell 控制臺中單獨運行這兩行代碼,它就可以作業。除了這兩行之外,變數 $USB_Drive 不會在其他任何地方使用。知道這可能是什么嗎?
這里有兩行:
$USB_Drive = Get-Disk | Where-Object BusType -eq USB | Out-GridView -Title 'Select USB Drive' -OutputMode Single
$Results = $USB_Drive | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -Passthru | New-partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem NTFS
和錯誤資訊:
ERROR: Clear-Disk : Das Argument für den Parameter "InputObject" kann nicht überprüft werden. Das Argument ist NULL. Geben Sie einen gültigen Wert für das Argument
ERROR: an, und führen Sie den Befehl erneut aus.
ERROR: In C:\Users\jorisbieg\Documents\SAPIEN\PowerShell Studio\Projects\ISODRIVE\ISODRIVE.Run.ps1:196 Zeichen:17
ERROR: ... USB_Drive | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -Passth ...
ERROR: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: CategoryInfo : InvalidData: (:) [Clear-Disk], ParameterBindingValidationException
ERROR: FullyQualifiedErrorId : ParameterArgumentValidationError,Clear-Disk
ERROR:
uj5u.com熱心網友回復:
您正在嘗試將 out-gridview 的輸出存盤在您的變數中,這將更接近您所追求的:
# Store the usb drive
$USB_Drive = Get-Disk | Where-Object BusType -eq USB
# display the usb drive
$USB_Drive | Out-GridView -Title 'Select USB Drive' -OutputMode Single
$Results = $USB_Drive | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -Passthru | New-partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem NTFS
uj5u.com熱心網友回復:
感謝您的回答,但這是因為變數不是全域創建的。如果我創建變數 $global:USB_Drive Global 一切正常。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/374236.html
