Tuesday, 14 July 2015

Powershell How Tos

How to Run a Script

.\filename.ps1

How to Fix Error: Digitally Signed

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy AllSigned -Force

How to Fix Error: Cannot be loaded because the execution of scripts is disabled

Run Powershell as Administrator, and execute this command on the prompt.
Set-ExecutionPolicy RemoteSigned

How to fix: Get-ADUser is not recognized as the name of the cmdlet, function, etc

Control Panel > Programs > Turn Windows features on or off
Enable: Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools
Note: This needs a server restart.
In Powershell prompt, Import-Module ActiveDirectory
(Note: Importing the activedirectory module needs to be run so that Get-ADUser will work on the script, include this line on the actual script.)


Command used to run the powershell script on Task Scheduler

powershell -executionpolicy bypass -file "C:\Users\juajen0Documents\_Tasks\Powershell\getLawlexUsersCheckAD.ps1"
Note: if the script is not functioning properly, you can add an option -noexit so that when you try running the task, you'd be able to see the powershell window with all the errors.



No comments:

Post a Comment