听起来像你需要改变$ConfirmPreference变量。
从Get-Help about_Preference_variables输出:
$ConfirmPreference
------------------
Determines whether Windows PowerShell automatically prompts you for
confirmation before running a cmdlet or function.
When the value of the $ConfirmPreference variable (High, Medium, Low) is
less than or equal to the risk assigned to the cmdlet or function (High,
Medium, Low), Windows PowerShell automatically prompts you for confirmation
before running the cmdlet or function.
If the value of the $ConfirmPreference variable is None, Windows PowerShell
never automatically prompts you before running a cmdlet or function.
因此,为了抑制那些确认消息,简单地做:
$ConfirmPreference = "None"
你也可以做到对每个cmdlet的基础上, -Confirm:$false参数:
Set-ADUser -Description $desc -Confirm:$false
请注意,这只适用于如果Cmdlet支持common parameter confirmation。它不会对自制cmdlet产生任何影响,并带有时髦的自制确认逻辑