我制作了一個用于將計算機加入域的批處理檔案。
Powershell -command " Add-Computer -DomainName blabla.com -Credential blabla\bla "
有效,但我也想添加 -Description 和輸入。
Powershell -command "
$date = Get-Date
$cred= read-host -prompt 'IT username'
Add-Computer -DomainName blabla.com -Description "joined domain by $cred date $date" -Credential blabla\$cred "
不作業。
Powershell -command " $date = Get-Date "
Powershell -command " $cred= read-host -prompt 'IT username' "
Powershell -command " Add-Computer -DomainName blabla.com -Description "joined domain by $cred date $date" -Credential blabla\$cred "
也沒有用。
請我需要幫助
uj5u.com熱心網友回復:
這需要在一次呼叫中完成powershell.exe。使用分號終止每個 PowerShell 陳述句并使用cmd行繼續符 CARET ^。
powershell -command ^
$date = Get-Date; ^
$cred= read-host -prompt 'IT username'; ^
Add-Computer -DomainName blabla.com -Description "joined domain by $cred date $date" -Credential blabla\$cred;
這需要是一次呼叫的原因是 PowerShell 的單獨呼叫不知道彼此做了什么。
這未經測驗。可能存在一些cmd語法問題,通常與參考有關。讓 .bat 檔案腳本呼叫 PowerShell 腳本會更容易。
powershell -NoLogo -NoProfile -File "%~dpDo-JoinDomain.ps1"
請注意,這Do不是批準的 PowerShell 動詞。使用命令Get-Verb找到你認為合適的。
uj5u.com熱心網友回復:
@echo off
Powershell -command " $date = Get-Date; $cred= read-host -prompt 'IT username'; add-Computer -DomainName tpicomp.com -Description "joined domain by $cred date $date" -Credential tpicomp\$cred "
感謝@lit 和@Compo,這是最終結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/440018.html
