1

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

Alexander Sinno
  • 554
  • 5
  • 24
  • 5
    I would say the best way to set this on many machines is to [use group policy, not a script](https://4sysops.com/archives/set-powershell-execution-policy-with-group-policy/). – briantist Feb 07 '17 at 20:15
  • @briantist will give this a shot and respond soon thanks. – Alexander Sinno Feb 07 '17 at 20:21
  • 1
    `Set-ExecutionPolicy RemoteSigned -Force -Scope MachinePolicy`? – Mathias R. Jessen Feb 07 '17 at 20:42
  • 1
    Err, yup, Group Policy is the way forward. Also useful for deploying profile scripts... – Simon Catlin Feb 07 '17 at 21:01
  • Confirmed that @briantist suggestion is the best possible method. All others work too in this case. Please post the answer if you'd like credit. – Alexander Sinno Feb 07 '17 at 22:53
  • 1
    @Badlarry I would, but it would amount to a link-only answer, or I would include the steps, which is more appropriate for [sf], so I'm not quite sure what to do. I would think deleting/closing the question? Having trouble resolving this one haha. – briantist Feb 07 '17 at 22:56
  • @briantist well, sorry about that... I suppose I could close the question so if some one else has the same question they could see this. Anyways thanks again Brian.... – Alexander Sinno Feb 07 '17 at 22:58
  • @Badlarry no need to be sorry, you started with a code problem then got a solution that sort of makes the question not about code; it's perfectly reasonable I'm just not certain what to do with it. Maybe ask on meta? – briantist Feb 07 '17 at 23:03
  • 1
    @briantist Meta created: http://meta.stackoverflow.com/questions/343225/asked-a-question-on-code-and-received-an-applicable-answer-for-server-fault – Alexander Sinno Feb 07 '17 at 23:11

1 Answers1

2

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

briantist
  • 45,546
  • 6
  • 82
  • 127