fbpx

How Do You Run A Script In Powershell?

Run A Script In PowerShell?

  1. Launch Windows PowerShell, and wait a moment for the PS command prompt to appear
  2. Navigate to the directory where the script lives

PS> cd C:\my_path\ (enter)

  1. Execute the script:

PS> .\run_import_script.ps1 (enter)

If it fails, you should check “setexecutionpolicy”

Steps:

  1. Launch a Windows PowerShell window run as an administrator.
  2. Navigate to the location where the reactivateUsers.ps1 is located on the central node.

1

  1. Update the PowerShell execution policy on the system to allow the script to run.

In the PowerShell window, enter set-executionpolicy unrestricted.

The system will prompt to confirm the change.

Enter the letter “Y” or press the enter key to change the execution policy setting.

4

PowerShell’s execution policy settings dictate what PowerShell scripts can be run on a Windows system. To run the reactivateUsers script, the execution policy needs to be changed.

  1. Run the PowerShell script reactivateUsers.ps1. PowerShell requires specifying a path with the script in order to run. If the PowerShell window is in the current directory of the script _._ can be used for specifying the current path. Assuming the PowerShell window is in the directory where reactivateUsers.ps1, enter .\reactivateUsers.ps1 to run the script.

3

  1. Set the execution policy back to the value it was before running the script using the set-executionpolicy commandlet.

5

  1. And you’re done!

What am I missing??

Or: you can run the PowerShell script from cmd.exe like this:

powershell -noexit “& “”C:\my_path\run_import_script.ps1″”” (enter)

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.