我正在尝试为超过 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在许多机器上。
来自链接:
To configure, navigate under Computer Configuration to
Policies\Administrative Templates\Windows Components\Windows PowerShell
You should see a setting called Turn on Script Execution
关于windows - 使用 PowerShell 脚本为数百名用户设置执行策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42099100/