Getting Started with Windows PowerShell


Firstly you have to Install PowerShell

As the initial step you need to make sure PowerShell is running in your system. Keep in mind that in this lab scenario Window 8.1 operating system is used. Since windows 8.1 comes with pre-installed PowerShell you can skip this step. For earlier versions such as Windows Vista you need to download and install PowerShell manually.

Download Link:

To Check the PowerShell version



get-host |select-object version 

get-host version



Set PowerShell’s Execution Policy

  • Restricted – PowerShell won’t run any scripts. This is PowerShell’s default execution policy.
  • AllSigned – PowerShell will only run scripts that are signed with a digital signature. If you run a script signed by a publisher PowerShell hasn’t seen before, PowerShell will ask whether you trust the script’s publisher.
  • RemoteSigned – PowerShell won’t run scripts downloaded from the Internet unless they have a digital signature, but scripts not downloaded from the Internet will run without prompting. If a script has a digital signature, PowerShell will prompt you before it runs a script from a publisher it hasn’t seen before.
  • Unrestricted – PowerShell ignores digital signatures but will still prompt you before running a script downloaded from the Internet.
  • Bypass – Everything runs without a warning. Be careful with this one.
  • Undefined – No policy is defined in the current scope. This is used to allow fall-back to policies defined in lower scopes (more details below) or to the OS defaults.

Check the current policy


01 get policy

Change the policy into RemoteSigned

Set-ExecutionPolicy RemoteSigned

02 set policy

Run Your First PowerShell script

Create a script file with following content. Name the file as MyScript.ps1

Write-Host "Hello, world"

Save the MyScript.ps1 file into following folder


03 capture

Run Following commands at PowerShell

PS C:\> Set-Location C:\Scripts

PS C:\Scripts> .\MyScript.ps1

04 run script

Alternatively you can use cmd.exe to run the scripts

In this case following script is used to get the information.

computer hostname = w

$computers = "w"

Get-WmiObject -Class win32_bios -cn $computers |

Format-table __Server, Manufacturer, Version -AutoSize

05 cmd prompt

You can use PowerShell scripts against Multiple Computers

In this scenario Windows Server 2012 R2 server domain environment is used to run the scripts.

Save following script in MyScript.ps1 file.

$computers = Get-Content -Path C:\Scripts\Computers.txt

Get-WmiObject -Class win32_bios -cn $computers -EA silentlyContinue |

Format-table __Server, Manufacturer, Version –AutoSize

Watermark Multiple Computers MyScript script file

And Make sure the computers list in the network is saved as a text file in Computers.txt.


Computers list Text File.png

The path of the text file should be


Run the PowerShell script

PS C:\> Set-Location C:\Scripts

PS C:\Scripts> .\MyScript.ps1

Watermark Multiple Computers powershell



How to Add Users With Windows PowerShell in Server 2016


In this tutorial basic PowerShell is used to create Active Directory users in Windows Server 2016

PS C:\> New-ADUser -Name “Jake Lawrence” -GivenName Mike -Surname Lawrence -SamAccountName Mike -UserPrincipalName

2016 AA AD-2017-04-24-17-51-22.png

2016 AA AD-2017-04-24-17-55-56

2016 AA AD-2017-04-24-18-06-54

watermark 2016-aa-ad-2017-04-24-18-12-30

Provide a password for the account

-AccountPassword (Read-Host -AsSecureString “AccountPassword”)

2016 AA AD-2017-04-24-18-24-07.png

Specify a path

-Path ‘OU=Company,DC=teche,DC=lk’

To enable the user account

-PassThru | Enable-ADAccount

To add bulk users

PS C:\> Import-Csv C:\users.csv | New-ADUser -PassThru | `

Set-ADAccountPassword -Reset `

-NewPassword (ConvertTo-SecureString -AsPlainText ‘Pa$$w0rd’ -Force) `

-PassThru | Enable-ADAccount

Create a .csv file with following format (MS Excel application is used)

kamal Deshapriya,kamal,Deshapriya,kamal,

csv file.png

watermark 2016-aa-ad-2017-04-24-18-51-24.png