我正在嘗試將我的 $file_data 變數轉換為整數,下面的代碼位會獲取我系統上保存在目錄中的計算機的編號。但是,當在 PowerShell 中運行時,即使變數是數字,我也會遇到錯誤。
The ' ' operator works only on numbers. The operand is a 'System.String'.
At D:\pscript\Intune.ps1:7 char:26
For ($file_data -le 130; $file_data ){
~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : OperatorRequiresNumber
我不確定我在哪里出錯了,任何幫助都會很棒。:)
Get-Content D:\pscript\temp\Directory.txt
$file_data = Get-Content D:\pscript\temp\Directory.txt
uj5u.com熱心網友回復:
要將字串轉換為整數,您可以對其進行型別轉換或在第一點宣告它。
[int] $file_data = 獲取內容 D:\pscript\temp\Directory.txt
但是,如果這需要作業,Directory.txt 應該具有適合整數類別的數字。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/487511.html
標籤:电源外壳
