Powershell Dump

Quick notes and syntax in regards to Powershell 2.0

-: to allow remote execution of script :-
– set-executionpolicy unrestricted

-: To find powershell version :-
– $psversiontable; will show you the version of Powershell, only good w/ Powershell 2.0

-: Get all the members and properties of an object :-
– $reboot = gwmi win32_operatingsystem -ComputerName abc
– $reboot | get-member

-: Listing WMI objects :-
– Get-WmiObject -List
– Get-WmiObject -List | where-object { $_.name -match/-notmatch ‘logicaldisk’ -AND $_.name -match/-notmatch ‘^cim’ }
– Get-WmiObject -class win32_process -filter “name = ‘kbsqs.exe’ and processid = ‘8802’”
– Get-WmiObject -class win32_process | get-member

-: Getting help for cmdlets & concepts :-
– Get-Help Test-Connection
– Get-Help Test-Connection -examples

-: Getting basic information about cmdlets :-
– Get-Command
– Get-Command | where-object { $_.name -match ‘Get-Member’ }

-: When to use: -contains, -like, -match :-
– -Contains: used w/ array; will not work with strings
– -like: used to perform wildcard search of strings; can be used to search arrays, however; results will not return as True/False but rather the element
— if ($date -like “*$title*”)
– -match: used to perform a regular expression
— if ($file_titles -match “$file_date”)

-: Tee-object :-
– get-process notepad | tee-object -file gp.log | stop-process: this will output any process that are killed to the log file gp.log in the present working dir
– get-process notepad | tee-object -variable gp | stop-process: this will output any process that are killed to the variable gp

-: Listing registered drives & mapping new one:-
– get-psdrive
– new-psdrive -name [driveName] -psprovider filesystem -root [pathtofolder]
– remove-psdrive [driveName]

-: List all the variables in the current PS instance :-
dir variable:

-: List all the available modules :-
Get-Module –ListAvailable
** get sql powershell plugins @ http://sqlpsx.codeplex.com/ **