Home Microsoft Windows Server 2008 and Server 2008 R2
Basic Powershell and Examples Print E-mail

Powershell needs installing as a feature on Windows Server 2008. Powershell is also backwards compatible with the standard command prompt (cmd.exe).

The powershell command prompt and running a powershell script:
PS C:\Windows\System32> .\myscript.ps1


A list of all the services and the status:
get-service

Stop a service:
stop-service -name spooler

Start a service:
start-service -name spooler

Help on a cmdlet:
get-help get-service

Get services details via WMI on a remote computer:
Get-WmiObject Win32_Service -computername lon-dc1

Use a variable to store a command:
$wmi = Get-WmiObject Win32_Service -computername lon-dc1
$wmi

List directory:
get-ChildItem (also dir)

Create a new powershell alias:
new-alias np notepad
np

List all powershell aliases:
get-alias

Note: Variables and Aliases created are per session:

Creating an AD user account with powershell using variables:
$ou=[ADSI] "LDAP://ou=London,dc=domain,dc=local"
$newUser=$ou.create("user","cn=JoeUser2")
$newUser.Put("sAMAccountName","JUser2")
$newUser.SetInfo()

Only allow remote scripts to run if they are signed:
set-executionpolicy remotesigned





 

vcplogo 

    

 

DISCLAIMER: All advice, tips, guides and other information on this website is provided as-is with no warranty or guarantee. While most information is correct to the best of my knowledge, I am not reponsible for any issues that may arise in using the information, and you do so at your own risk. As always before doing anything; check, double check, test and always make a backup.

 

Help VMadmin

All resources on this site are provided absolutley free. However it takes time and money to keep the site running. If any information has been helpful to you or your company, and you wish to make a donation to help keep VMadmin.co.uk running you can do so via paypal, and it would be much appreciated.

Click to donate to VMadmin.co.uk via paypal.