Wednesday, May 14, 2014

Useful PowerShell Commands

1) Command to get PowerShell Version:
                         
$PSVersionTable.PSVersion


2) Command to get the current directory of the PowerShell Script:

a)  In PowerShell 3.0

$PSScriptRoot


b) In PowerShell 2.0

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition


3) Read xml file into PowerShell

$xmlFilePath = "C:\SampleXmlFile.xml"

[xml]$xmlFileContents = Get-Content $xmlFilePath