0
我試圖通過PowerShell腳本將打印機部署到組織中的PC。腳本本身通過組策略部署在機器啓動時運行。當測試OU中的機器啓動時,它會坐下來,請無限期地等待,腳本永遠不會完成。如果您手動執行該腳本,該腳本將起作用我不會詳細介紹它,但是通過組策略直接部署打印機不是一種選擇。通過GPO打印機部署的PowerShell啓動腳本
PowerShell腳本
# Print File Server Path
$printsrv = "\\Servername\Deploy\"
# Check FTP Server Status
$file = ($env:computername + '.csv')
$num = 0
IF ((Test-Path ($printsrv + $file)) -eq $false) {
Do {
Start-Sleep -Seconds 5
$num = $num + 1
} Until ((Test-Path ($printsrv + $file)) -eq $true -or $num -eq 3)
}
if ((Test-Path ($printsrv + $file)) -eq $false) {exit}
# Create Printers
$print = Import-Csv ($printsrv + $file)
$num = 0
do {
(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($print.p_address[$num])
$num = $num + 1
} Until ($num -eq $print.Count)
#Set Default
$num = 0
Do {
$contains = $Print.Def_Bit[$num].Contains(1)
$Default = $print.P_Address[$num]
$num++
} until ($contains -eq $true -or $num -eq $print.Count)
(New-Object -ComObject WScript.Network).SetDefaultPrinter($Default)
Remove-Item -Path ($printsrv + $file)
CSV文件
#TYPE System.Data.DataRow
"P_Address","DEF_Bit"
"\\server\printer",""
"\\server\printer","True"
添加一些'寫主機'來找到它的位置 – 2013-03-15 16:21:04