Learning powershell

Welcome Forums General PowerShell Q&A Learning powershell

Viewing 5 reply threads
  • Author
    Posts
    • #265613
      Participant
      Topics: 2
      Replies: 4
      Points: 34
      Rank: Member

      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=”[email protected]

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

      }

    • #265625
      Participant
      Topics: 8
      Replies: 670
      Points: 2,640
      Helping Hand
      Rank: Community Hero

      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.

    • #265634
      Participant
      Topics: 2
      Replies: 4
      Points: 34
      Rank: Member

      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

    • #265643
      Participant
      Topics: 8
      Replies: 670
      Points: 2,640
      Helping Hand
      Rank: Community Hero

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

    • #265718
      Participant
      Topics: 2
      Replies: 4
      Points: 34
      Rank: Member

      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: (:) [Set-ExecutionPolicy], SecurityException
      + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

    • #265820
      Participant
      Topics: 0
      Replies: 5
      Points: 9
      Rank: Member

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

Viewing 5 reply threads
  • You must be logged in to reply to this topic.