我需要更改多個用戶“主”目錄中 DefaultPrint.ini 檔案中的值。
我已經設法制作了一個 powershell 腳本來更改單個用戶的值,但我正在努力使腳本接受多個用戶。
$User = "Max"
$IniPath = "\\Network1\Home\$User\"
foreach ($User in $User)
{
$IniFile = "$IniPath\DefaultPrint.ini"
$IniText = Get-Content -Path $IniFile
$NewText = $IniText.Replace("Old_Priter","New_Printer")
Set-Content -Path $IniFile -Value $NewText -Force
}
我需要輸入以查找檔案的目錄基于用戶名,因此我需要將檔案更改為:\Network1\Home\Max
\Network1\Home\John
\Network1\Home\Sophia
等
上面的腳本適用于單個用戶,我正在嘗試通過 .csv 檔案使其適應多個用戶
我嘗試了以下
$User = "Max","John","Sophia"
但它不會分離用戶目錄而是將它們聚集在一起?(\Network1\Home\Max John Sophia)
我還嘗試通過 csv 匯入,因為我需要對 200 多個用戶執行此操作
$User = (Import-Csv -Path .\Users.csv).User
但它最終做同樣的事情,我做錯了什么?
uj5u.com熱心網友回復:
你需要移動這個陳述句:
$IniPath = "\\Network1\Home\$User\"
在回圈內部,以便$user每次都使用正確的路徑更新路徑,然后重命名$User回圈外部使用的變數($Users這里似乎是一個合適的名稱):
$Users = -split "Max John Sophia"
foreach ($User in $Users)
{
$IniPath = "\\Network1\Home\$User\"
$IniFile = "$IniPath\DefaultPrint.ini"
$IniText = Get-Content -Path $IniFile
$NewText = $IniText.Replace("Old_Priter","New_Printer")
Set-Content -Path $IniFile -Value $NewText -Force
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316429.html
標籤:电源外壳
上一篇:來自輸入的變數
