Reputation: 564
I am trying to set the execution policy for more than 150 users.... I wrote a script, it runs with out error, but I confirmed with the user that the change wasn't made...
$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}
}
Any idea why this isn't working?
If there is a more practical way to do this please let me know if this is over-complicating a simple situation
Upvotes: 1
Views: 1183
Reputation: 47862
The best way to achieve this is generally to use Group Policy to set execution policy on a number of machines.
From the 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
Upvotes: 2