Thursday, 19 September 2013

PowerShell - Usefull commands

Update help definition  from online.

You need to run this command under administrator rights.

PS C:\Windows\system32> Update-Help
(I have read, that it gets updated almost every week)

PowerShell can run with wildcards : *

PS C:\Windows\system32> help *service*

Name                              Category  Module                    Synopsis                                                                                                               
----                              --------  ------                    --------                                                                                                               
Get-Service                       Cmdlet    Microsoft.PowerShell.M... Gets the services on a local or remote computer.                                                                       
New-Service                       Cmdlet    Microsoft.PowerShell.M... Creates a new Windows service.                                                                                         
New-WebServiceProxy               Cmdlet    Microsoft.PowerShell.M... Creates a Web service proxy object that lets you use and manage the Web service in Windows PowerShell.                 
Restart-Service                   Cmdlet    Microsoft.PowerShell.M... Stops and then starts one or more services.                                                                            
Resume-Service                    Cmdlet    Microsoft.PowerShell.M... Resumes one or more suspended (paused) services.                                                                       
Set-Service                       Cmdlet    Microsoft.PowerShell.M... Starts, stops, and suspends a service, and changes its properties.                                                     
Start-Service                     Cmdlet    Microsoft.PowerShell.M... Starts one or more stopped services.                                                                                   
Stop-Service                      Cmdlet    Microsoft.PowerShell.M... Stops one or more running services.                                                                                    
Suspend-Service                   Cmdlet    Microsoft.PowerShell.M... Suspends (pauses) one or more running services.         

Get full help information about command including examples

PS C:\Windows\system32> help Get-Service -full

What version of PowerShell do I have Installed

  1. $PSVersionTable
  2. $host.version

Get gui for command

PS C:\Windows\system32> Show-Command Start-Process

Get members of commands:

This command shows all information what all I can get get.

PS D:\Scripts> get-service | get-member

PowerShell function parameters
If you are using parameters use param definition in function instead in bracets of the function name:

function WebConfig-SetAppConfigValueForKey{

Executing script path

If you are executing script you will be able to get path of the script which gets executed.

function Test(){
    $scriptpath = $MyInvocation.MyCommand.Path
    write-host $scriptpath


If you execute the script without file you will get null