Scripting >> Powershell >> Command Examples

 

Command Result
get-help displays the help start page in continuous page
help displays the help start page pausing at every page

get-help topic
or
help topic

displays help on that topic
help *
or
get-help *
lists all help topics
set-Date
sets system date.  Examples:-

Set-Date -date "6/1/2006 8:30 AM"
Set-Date (Get-Date).AddDays(2)
Set-Date (Get-Date).AddHours(-1)
Set-Date -adjust 1:37:0
get-Date gets system date
copy-Item Copies file.  Examples:-

Copy-Item c:\scripts\test.txt c:\test
Copy-Item c:\scripts\* c:\test
Copy-Item c:\scripts\*.txt c:\test
Copy-Item c:\scripts c:\test -recurse


 
New-Item

Create new file or directory

Example:-

New-Item c:\scripts\Windows PowerShell -type directory
New-Item c:\scripts\new_file.txt -type file
New-Item c:\scripts\new_file.txt -type file -force


Remove-Item
Delete file or folder.  Examples:-

Remove-Item c:\scripts\test.txt
Remove-Item c:\scripts\*
Remove-Item c:\scripts\* -recurse
Remove-Item c:\scripts\* -exclude *.wav
Remove-Item c:\scripts\* -include .wav,.mp3
Remove-Item c:\scripts\* -include *.txt -exclude *test*


Get-WmiObject

Get-WmiObject Win32_LogicalDisk | Select-Object deviceid,size,freespace

shows the logical disk id e.g. C: the size of the disk and free space on the disk

Get-WmiObject Win32_Product | Sort-Object Name | Format-Table Vendor, Name, Version

shows list of Software installed on the computer

get-eventlog

get-eventlog application | where {$_.message.contains("error") -eq "true"}

shows events from application event log where the message contains keyword "error"

get-eventlog system | where {$_.message.contains("error") -eq "true"}

shows events from system event log where the message contains keyword "error"

get-executionpolicy show the current execution policy 
set-executionpolicy sets the execution policy
possible values are Restricted | AllSigned | RemoteSigned | Unrestricted

 

 

 

 


 

References

[1]  https://technet.microsoft.com/en-us/library/hh848794.aspx

https://technet.microsoft.com/en-us/library/ee176961.aspx