Getting Started With PowerShell - Pt2 - How to Run Scripts
In my last post Getting Started With PowerShell - pt1 I covered the basics of how to use PowerShell. In this part I will go over some more advances uses and functions. Like how to run a PowerShell Script.
One Key part of PowerShell is being able to write and run your own scripts. In order to run a PowerShell script the script must meet the criteria of PowerShell's Execution Policy that is set on the local device. To see what execution policy PowerShell is set to you can run the Get-ExecutionPolicy command.
On my device the policy is set to Restricted and this is the default for PowerShell. PowerShell has 6 different polices AllSigned, Bypass, RemoteSigned, Restricted, Undefined, Unrestricted. We will get into what each policy is for later but fore now we will use the policy that is a good mix of security and ease of use, RemoteSigned. To change the Policy we run the Set-ExecutionPolicy Command followed by the name of the policy we want to use.
When you set the policy PowerShell will give you a warning choose A then hit enter
Now that the Policy has been changed so that we can run a script we need a script to run. It just so happens that we have one ready for you
Download the Script and unzip the file. Inside you will see a .ps1 file this is a PowerShell script file. Extract the file to your desktop then we will point PowerShell to your desktop. Run the Set-Location command Followed by the path to your desktop.
As you can see the left side path now shows that we are at C:\users\KrisGross\Desktop. Since this is where are script is we can now start the script by typing ".\" followed by the name of the script.
As you can see this script returns a nice amount of information about the device. However just like with a PowerShell command script can have parameters too this script has the -ComputerName parameter that allows us to remotely gather info about another computer on our network. Just like with command we can use the Get-Help Command that tells us more about the script and how to use it. Before we run the get-help command lets clear the PowerShell window to do this simply type