Learning powershell

I am in college learning powershell for the first time. I was given an assignment to use powershell to add some users to an active directory. I managed to cobble together a very rudimentary script that did the job, but missed a part of the lab that said to give all the user passwords as well. I deleted the users, made a minor edit to the script to add the passwords, then tried again. However, when I tried I was given an error saying that the “cannot be loaded because running scripts is disabled on this system”. I ran the get-executionpolicy -list command and found

MachinePolicy Restricted
UserPolicy Restricted
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted

 

If anyone could tell me what went wrong and how to fix it that would be greatly appreciated. This was the script I used

 

$newuserlist=Import-Csv “C:\userexport.csv”

foreach ($user in $newuserlist) {

$fullname=$user.FullName

$password=“P@ssw0rd”

New-ADUser -passthru -DisplayName $FullName -Name $FullName -AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force)

}

Change your execution policy to remotesigned. If you’re running as admin, it will change the localmachine and currentuser policy by default unless you’ve previously defined the currentuser, which it doesn’t appear you did. You can change just the currentuser scope by adding -Scope CurrentUser If you’re not running as admin specify the currentuser scope.

I am signed in as admin. When I try changing any of the policies I get this error

Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined
at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Restricted.

The thing is I don’t know what policy is overriding it. Like I said in the original post, the only thing I did after my script worked the first time is delete the created users and add the password commands. I didn’t touch anything about policies

Which one didn’t change? Currentuser is my bet. Add -Scope Currentuser

I tried adding that as well and got the same message

PS C:\Users\Administrator> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined
at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Restricted. Type
“Get-ExecutionPolicy -List” to view your execution policy settings. For more information please see “Get-Help Set-ExecutionPolicy”.
At line:1 char:1

  • Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  • CategoryInfo : PermissionDenied: (:slight_smile: [Set-ExecutionPolicy], SecurityException
  • FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

Use Set-executionpolicy Unrestricted and try to run the code.