使用 PowerShell 脚本为数百名用户设置执行策略

Set-ExecutionPolicy for hundreds of users with PowerShell script

我正在尝试为超过 150 个用户设置执行策略....我写了一个脚本,它运行时没有错误,但我向用户确认 没有进行更改...

$worstationobject = New-Object psobject Hostname

Add-Member -InputObject $worstationobject -MemberType NoteProperty -Name 'CORP\mkatherine'  -Value 'FooBar23'
Add-Member -InputObject $worstationobject -MemberType NoteProperty -Name 'CORP\jshmoe'  -Value 'FooBar12'


function Get-MemberValues {
   $wslist = $worstationobject.psobject.Members |
   ? {$_.Membertype -eq "noteproperty"} | 
   %{ $_.Value }
   $wslist -join ","
}
function Set-ThePolicies {
   $devices = Get-MemberValues
   Invoke-Command -InputObject $devices -ScriptBlock {Set-ExecutionPolicy RemoteSigned -Force}
}

知道为什么这不起作用吗?

如果有更实用的方法,请告诉我这是否使简单情况过于复杂

实现此目的的最佳方法通常是 use Group Policy to set execution policy 在多台机器上。

来自link:

To configure, navigate under Computer Configuration to Policies\Administrative Templates\Windows Components\Windows PowerShell You should see a setting called Turn on Script Execution