PowerShell for Lazy Persons

PowerShell logo

PowerShell logo


%
?
A:
ac
Add-Computer
Add-Content
Add-History
Add-Member
Add-PSSnapin
Add-Type
asnp
B:
C:
cat
cd
cd..
cd\
chdir
Checkpoint-Computer
clc
clear
Clear-Content
Clear-EventLog
Clear-History
Clear-Host
Clear-Item
Clear-ItemProperty
Clear-Variable
clhy
cli
clp
cls
clv
compare
Compare-Object
Complete-Transaction
Connect-WSMan
ConvertFrom-Csv
ConvertFrom-SecureString
ConvertFrom-StringData
Convert-Path
ConvertTo-Csv
ConvertTo-Html
ConvertTo-SecureString
ConvertTo-Xml
copy
Copy-Item
Copy-ItemProperty
cp
cpi
cpp
cvpa
d
D:
dbp
Debug-Process
del
diff
dir
Disable-ComputerRestore
Disable-PSBreakpoint
Disable-PSRemoting
Disable-PSSessionConfiguration
Disable-WSManCredSSP
Disconnect-WSMan
dp
E:
ebp
echo
Enable-ComputerRestore
Enable-PSBreakpoint
Enable-PSRemoting
Enable-PSSessionConfiguration
Enable-WSManCredSSP
Enter-PSSession
epal
epcsv
epsn
erase
etsn
excel
Exit-PSSession
Export-Alias
Export-Clixml
Export-Console
Export-Counter
Export-Csv
Export-FormatData
Export-ModuleMember
Export-PSSession
exsn
F:
fc
FindDefaultPrinter
fl
foreach
ForEach-Object
Format-Custom
Format-List
Format-Table
Format-Wide
ft
fw
G:
gal
gbp
gc
gci
gcm
gcs
gdr
Get-Acl
Get-Alias
Get-AuthenticodeSignature
Get-ChildItem
Get-Command
Get-ComputerRestorePoint
Get-Content
Get-Counter
Get-Credential
Get-Culture
Get-Date
Get-Event
Get-EventLog
Get-EventSubscriber
Get-ExecutionPolicy
Get-FormatData
Get-Help
Get-History
Get-Host
Get-HotFix
Get-Item
Get-ItemProperty
Get-Job
Get-Location
Get-Member
Get-Module
Get-PfxCertificate
Get-Process
Get-PSBreakpoint
Get-PSCallStack
Get-PSDrive
Get-PSProvider
Get-PSSession
Get-PSSessionConfiguration
Get-PSSnapin
Get-Random
Get-Service
Get-TraceSource
Get-Transaction
Get-UICulture
Get-Unique
Get-Variable
Get-Verb
Get-WinEvent
Get-WmiObject
Get-WSManCredSSP
Get-WSManInstance
ghy
gi
gjb
gl
gm
gmo
gp
gps
group
Group-Object
gsn
gsnp
gsv
gu
gv
gwmi
h
H:
help
history
I:
icm
iex
ihy
ii
Import-Alias
Import-Clixml
Import-Counter
Import-Csv
Import-LocalizedData
Import-Module
Import-PSSession
ImportSystemModules
Invoke-Command
Invoke-Expression
Invoke-History
Invoke-Item
Invoke-WmiMethod
Invoke-WSManAction
ipal
ipcsv
ipmo
ipsn
ise
iwmi
J:
Join-Path
K:
kill
L:
Limit-EventLog
lp
ls
M:
man
md
measure
Measure-Command
Measure-Object
mi
mkdir
more
mount
move
Move-Item
Move-ItemProperty
mp
mv
N:
nal
ndr
New-Alias
New-Event
New-EventLog
New-Item
New-ItemProperty
New-Module
New-ModuleManifest
New-Object
New-PSDrive
New-PSSession
New-PSSessionOption
New-Service
New-TimeSpan
New-Variable
New-WebServiceProxy
New-WSManInstance
New-WSManSessionOption
ni
nmo
nsn
nv
O:
ogv
oh
Out-Default
Out-File
Out-GridView
Out-Host
Out-Null
Out-Printer
Out-String
P:
popd
Pop-Location
pro
prompt
ps
pushd
Push-Location
pwd
Q:
r
R:
rbp
rcjb
rd
rdr
Read-Host
Receive-Job
Register-EngineEvent
Register-ObjectEvent
Register-PSSessionConfiguration
Register-WmiEvent
Remove-Computer
Remove-Event
Remove-EventLog
Remove-Item
Remove-ItemProperty
Remove-Job
Remove-Module
Remove-PSBreakpoint
Remove-PSDrive
Remove-PSSession
Remove-PSSnapin
Remove-Variable
Remove-WmiObject
Remove-WSManInstance
ren
Rename-Item
Rename-ItemProperty
Reset-ComputerMachinePassword
Resolve-Path
Restart-Computer
Restart-Service
Restore-Computer
Resume-Service
ri
rjb
rm
rmdir
rmo
rni
rnp
rp
rsn
rsnp
rv
rvpa
rwmi
S:
sajb
sal
saps
sasv
sbp
sc
select
Select-Object
Select-String
Select-Xml
Send-MailMessage
set
Set-Acl
Set-Alias
Set-AuthenticodeSignature
Set-Content
Set-Date
Set-ExecutionPolicy
Set-Item
Set-ItemProperty
Set-Location
Set-PSBreakpoint
Set-PSDebug
Set-PSSessionConfiguration
Set-Service
Set-StrictMode
Set-TraceSource
Set-Variable
Set-WmiInstance
Set-WSManInstance
Set-WSManQuickConfig
Show-EventLog
si
sl
sleep
sort
Sort-Object
sp
spjb
Split-Path
spps
spsv
start
Start-Job
Start-Process
Start-Service
Start-Sleep
Start-Transaction
Start-Transcript
Stop-Computer
Stop-Job
Stop-Process
Stop-Service
Stop-Transcript
Suspend-Service
sv
swmi
T:
TabExpansion
tee
Tee-Object
Test-ComputerSecureChannel
Test-Connection
Test-ModuleManifest
Test-Path
Test-WSMan
Trace-Command
type
U:
Undo-Transaction
Unregister-Event
Unregister-PSSessionConfiguration
Update-FormatData
Update-List
Update-TypeData
Use-Transaction
V:
W:
Wait-Event
Wait-Job
Wait-Process
where
Where-Object
wjb
write
Write-Debug
Write-Error
Write-EventLog
Write-Host
Write-Output
Write-Progress
Write-Verbose
Write-Warning
X:
Y:
Z:

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
Get-Date -displayhint date
Get-Date -displayhint time
$A = Get-Date 5/1/2006
$A = Get-Date “5/1/2006 7:00 AM”
Get-Date).AddMinutes(137)

New-TimeSpan $(Get-Date) $(Get-Date -month 12 -day 31 -year 2006)
$(Get-Date)
New-TimeSpan $(Get-Date) $(Get-Date -month 12 -day 31 -year 2006)
New-TimeSpan $(Get-Date) $(Get-Date -month 12 -day 31 -year 2006 -hour 23 -minute 30)

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 c:\scripts\Windows\PowerShell -type directory
New-Item c:\scripts\new_file.txt -type file
New-Item : The file ‘C:\scripts\new_file.txt’ already exists.
New-Item c:\scripts\new_file.txt -type file -force
New-Item c:\scripts\new_file.txt -type file -force -value “This is text added to the file”

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*
Remove-Item c:\scripts\*.vbs -whatif
Remove-Item alias:\show

Set-Location env:\

Move-Item c:\scripts\test.zip c:\test
Move-Item c:\scripts\*.zip c:\test
Move-Item c:\scripts\test.zip c:\test -force
Move-Item c:\scripts\950.log c:\test\mylog.log

Rename-Item c:\scripts\test.txt new_name.txt

Get-ChildItem -recurse
Get-ChildItem env:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Get-ChildItem c:\scripts\*.* -include *.txt,*.log
Get-ChildItem c:\scripts\*.* -exclude *.txt,*.log
Get-ChildItem c:\scripts\*.* | Sort-Object length
Get-ChildItem c:\scripts\*.* | Sort-Object length -descending
$(Get-Item c:\scripts).lastaccesstime
$(Get-Item hkcu:\software).subkeycount
Get-Item hkcu:\software | Get-Member

Test-Path c:\scripts\test.txt
Test-Path c:\scripts\*.wma
Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion

Get-Help *
Get-Help Get-Member
Get-Help Get-Member | more

Get-Command
Get-Command | Format-List *
Get-Command | Select-Object name
Get-Command | Get-Help | Out-File c:\scripts\help.txt

Get-Host

Get-EventLog -list | Get-Member

Get-Process | Select-Object name, npm
New-Object -com scripting.filesystemobject | Get-Member

Get-PSProvider

Add-Content c:\scripts\test.txt “The End”
Add-Content c:\scripts\test.txt “`nThe End”

Write-Host `a
$A = Get-Date; Add-Content c:\scripts\*.log $A

Get-Content c:\scripts\test.txt | Select-String “Failed” -quiet
Get-Content c:\scripts\test.txt | Select-String “Failed” -quiet -casesensitive

Get-Process | Tee-Object -file c:\scripts\test.txt

Clear-Content c:\scripts\test.txt
Clear-Content c:\scripts\e*
Clear-Content c:\scripts\test.xls
Clear-Content c:\scripts\test.doc

Get-Process | ConvertTo-Html | Set-Content c:\scripts\test.htm
Get-Process | ConvertTo-Html name,path,fileversion | Set-Content c:\scripts\test.htm
Get-Process | ConvertTo-Html name,path,fileversion -title “Process Information” | Set-Content c:\scripts\test.htm
Get-Process | ConvertTo-Html name,path,fileversion -title “Process Information” -body “Information about the processes running on the computer.” | Set-Content c:\scripts\test.htm
Get-Process | ConvertTo-Html name,path,fileversion -title “Process Information” -body “<H2>Information about the processes running on the computer.</H2>” | Set-Content c:\scripts\test.htm
Get-Content c:\scripts\test.txt
Get-Content c:\scripts\test.txt | Foreach-Object {Get-Wmiobject -computername $_ win32_bios}

ForEach-Object {Get-Wmiobject -computername $_ win32_bios}

Get-Content c:\scripts\test.txt | Measure-Object
Get-Content c:\scripts\test.txt -totalcount 5
Get-Content c:\scripts\test.txt | Select-Object -last 5
Get-Content c:\scripts\test.txt
Get-Content c:\scripts\test.txt | Foreach-Object {Get-Wmiobject -computername $_ win32_bios}

Get-Content c:\scripts\test.txt -totalcount 5
Get-Content c:\scripts\test.txt | Select-Object -last 5

Import-Csv c:\scripts\test.txt
Import-Csv c:\scripts\test.txt | Where-Object {$_.department -eq “Finance”}
Import-Csv c:\scripts\test.txt | Where-Object {$_.department -ne “Finance”}
Import-Csv c:\scripts\test.txt | Where-Object {$_.department -eq “Finance” -and $_.title -eq “Accountant”}
Import-Csv c:\scripts\test.txt | Where-Object {$_.department -eq “Research” -or $_.title -eq “Accountant”}

Get-ChildItem c:\scripts | Export-Clixml c:\scripts\files.xml
$A = Import-Clixml c:\scripts\files.xml
$A | Sort-Object length

Get-Process | Export-Csv c:\scripts\test.txt
Get-Process | Export-Csv c:\scripts\test.txt -encoding “unicode”
Get-Process | Export-Csv c:\scripts\test.txt -notype

PS C:\Documents and Settings\gstemp> Get-Process | Export-Csv c:\scripts\test.txt

Get-Process | Export-Csv c:\scripts\test.txt -force
Get-Process | Export-Clixml c:\scripts\test.xml
Get-Process | Export-Clixml c:\scripts\test.xml -noclobber
Export-Clixml : File C:\scripts\test.xml already exists and NoClobber was specified.
Get-Process | Out-File c:\scripts\test.txt
Get-Process | Out-File c:\scripts\test.txt -width 120

Set-Content c:\scripts\test.txt “This is a test”
Get-Service | Group-Object status

Get-ChildItem c:\scripts | Group-Object extension
Get-ChildItem c:\scripts | Group-Object extension | Sort-Object count

Import-Csv c:\scripts\test.txt | Measure-Object score -ave -max -min
Import-Csv c:\scripts\test.txt | Sort-Object score -ascending | Select-Object -first 5
Import-Csv c:\scripts\test.txt | Sort-Object score | Select-Object -first 5

$A = Get-Process
$B = Get-Process
Compare-Object $A $B
Compare-Object $(Get-Content c:\scripts\x.txt) $(Get-Content c:\scripts\y.txt)

$A = Get-Content c:\scripts\x.txt
$B = Get-Content c:\scripts\y.txt
Compare-Object A$ B$
Compare-Object $(Get-Content c:\scripts\x.txt) $(Get-Content c:\scripts\y.txt) -includeequal

Get-Service | Format-List

Get-Process | Format-Wide
Get-Process | Format-Wide -columns 4
Get-Process | Format-Wide -autosize
Get-Process | Where-Object {$_.handles -ge 200}
Get-Process | Where-Object {$_.handles -gt 200 -and $_.name -eq “svchost”}
Get-Process | Where-Object {$_.handles -gt 200 -or $_.name -eq “svchost”}

Get-ChildItem c:\scripts | Where-Object {$_.length -gt 100000}
Get-ChildItem c:\scripts | Where-Object {$_.name -like “*test*”}

Get-Content c:\scripts\test.txt | Sort-Object | Get-Unique

Get-ChildItem c:\scripts
Get-ChildItem “hklm:\software\microsoft\windows\currentversion\uninstall\windows media player”
Get-ItemProperty “hklm:\software\microsoft\windows\currentversion\uninstall\windows media player”
Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath}

Get-Process | Write-Host $_.name -foregroundcolor cyan
Get-Process | ForEach-Object {Write-Host $_.name -foregroundcolor cyan}

Start-Sleep -s 10
Start-Sleep -m 10000

Get-Process | Output-Printer
Get-Process | Output-Printer “IT Department Printer”

$Name = Read-Host “Please enter your name”
$Password = Read-Host -assecurestring “Please enter your password”

Get-ChildItem c:\windows\*.* | Sort-Object length -descending | Select-Object -first 3
Select-Object -first 3
Get-ChildItem c:\windows\*.* | Sort-Object length -descending | Select-Object -last 3

Get-Process | Select-Object name,id | Format-List
Get-Process | Select-Object *
Get-Process | Select-Object * -exclude site,container

Get-EventLog system -newest 5 | Sort-Object eventid
Get-EventLog system -newest 5 | Sort-Object eventid -descending

Get-ChildItem c:\scripts | Sort-Object extension,length

Write-Host “This is a message”
Write-Host “This is red text on a yellow background” -foregroundcolor red -backgroundcolor yellow
Write-Host “Data for ” -nonewline; Write-Host “atl-ws-01″ -foregroundcolor red -backgroundcolor yellow -nonewline; Write-Host ” retrieved May 12, 2006″

Invoke-Item c:\windows\system32\calc.exe
Invoke-Item c:\scripts\*.txt

Invoke-Expression c:\scripts\test.ps1
& c:\scripts\test.ps1
c:\scripts\test.ps1
Invoke-Expression “c:\my scripts\test script.ps1”

Measure-Command {Get-Service | Export-Clixml c:\scripts\test.xml}
Measure-Command {c:\scripts\test.ps1}

Set-ExecutionPolicy RemoteSigned
Get-ExecutionPolicy

Get-AuthenticodeSignature “C:\Program Files\Windows PowerShell\v1.0\Windows PowerShell.exe”
Get-AuthenticodeSignature “C:\Program Files\Windows PowerShell\v1.0\Windows PowerShell.exe”

Get-Acl c:\scripts | Format-List
Get-Acl HKCU:\Software\Microsoft\Windows
Get-Acl c:\scripts\*.log | Format-List

Get-Service
Get-Service | Where-Object {$_.status -eq “stopped”}
Get-Service | Where-Object {$_.status -eq “running”}
Get-Service | Sort-Object status,displayname

Get-EventLog -list
Get-EventLog -list | Where-Object {$_.logdisplayname -eq “System”}
Get-EventLog system
Get-EventLog system -newest 3
Get-EventLog system -newest 3 | Format-List
Get-EventLog “Windows PowerShell” | Where-Object {$_.EventID -eq 403}
Get-EventLog “Windows PowerShell” | Group-Object eventid | Sort-Object Name

Set-Service clipsrv -startuptype “manual”
Set-Service “ati hotkey poller” -description “This is ATI HotKey Poller service.”

Suspend-Service tapisrv
Suspend-Service -displayname “telephony”

Resume-Service tapisrv
Resume-Service -displayname “telephony”

Get-WmiObject win32_bios
Get-WmiObject win32_bios -computername atl-fs-01
Get-WmiObject -namespace root\ccm -class sms_client -computername atl-fs-01
get-wmiobject -namespace root\ccm -class ccm_installedcomponent -computername atl-fs-01 | Select-Object displayname,name,version | Sort-Object displayname

Set-WmiObject win32_bios | Select-Object *

Get-WmiObject win32_bios | Select-Object -excludeproperty “_*”
Get-WmiObject win32_bios | get-member

BiosCharacteristics Property System.UInt16[] BiosCharacte…
BIOSVersion Property System.String[] BIOSVersion …
BuildNumber Property System.String BuildNumber {g…

Get-Process
Get-Process winword
Get-Process winword,explorer
Get-Process w*
Get-Process | Select-Object name,fileversion,productversion,company
Get-Process | Get-Member

Stop-Service btwdins
Stop-Service -displayname “Bluetooth service”

Start-Service btwdins
Start-Service -displayname “Bluetooth service”

Restart-Service btwdins
Restart-Service btwdins,alerter
Restart-Service -displayname “bluetooth service”

Stop-Process 3512
Stop-Process -processname notepad
Stop-Process -processname note*

New-Alias show Get-ChildItem
C:\Documents and Settings\gstemp\My Documents\PSConfiguration
Get-Variable profile | Format-List
Set-Alias show Get-ChildItem
Import-Alias c:\scripts\alias.txt

Get-Alias
Get-Alias -name f*

Set-Alias show Get-ChildItem
Remove-Item alias:\show

Export-Alias c:\scripts\test.txt
Export-Alias c:\scripts\test.ps1 -as “script”

set-alias -Name:”ac” -Value:”Add-Content” -Description:”” -Option:”ReadOnly, AllScope”
set-alias -Name:”clc” -Value:”Clear-Content” -Description:”” -Option:”ReadOnly, AllScope”
set-alias -Name:”cli” -Value:”clear-item” -Description:”” -Option:”ReadOnly, AllScope”

Export-Alias c:\scripts\test.ps1 -name x* -as “script”
Export-Alias c:\scripts\test.txt -noclobber
Export-Clixml : File C:\scripts\test.txt already exists and NoClobber was specified.

Get-Location
Get-Location -psdrive hkcu

New-PSDrive -name X -psprovider FileSystem -root c:\scripts
Set-Location x:
New-PSDrive -name Y -psprovider Registry -root HKCU:\Software\Microsoft\Windows\CurrentVersion
C:\Documents and Settings\gstemp\My Documents\PSConfiguration
Get-Variable profile | Format-List
New-PSDrive -name X -psprovider FileSystem -root c:\scripts

Get-PSDrive
Get-PSDrive | Format-List
Get-PSDrive c
Get-PSDrive h*

Set-Location c:\scripts
Set-Location HKCU:\Software\Microsoft\Windows
Convert-Path x:

Set-Location hkcu:\software\microsoft\windows
Convert-Path hkcu:\software\microsoft\windows
HKEY_CURRENT_USER\software\microsoft\windows
Remove-PSDrive y

Get-Location
Get-Location -psdrive hkcu

New-PSDrive -name X -psprovider FileSystem -root c:\scripts
Set-Location x:
New-PSDrive -name Y -psprovider Registry -root HKCU:\Software\Microsoft\Windows\CurrentVersion
C:\Documents and Settings\gstemp\My Documents\PSConfiguration
Get-Variable profile | Format-List
New-PSDrive -name X -psprovider FileSystem -root c:\scripts

Get-PSDrive
Get-PSDrive | Format-List
Get-PSDrive c
Get-PSDrive h*

Set-Location c:\scripts
Set-Location HKCU:\Software\Microsoft\Windows

Convert-Path x:
Set-Location hkcu:\software\microsoft\windows
Convert-Path hkcu:\software\microsoft\windows
Remove-PSDrive y

Get-Culture
Get-History
Get-History 32 -count 32

Invoke-History 3
Invoke-History 3;Invoke-History 4

Get-History | Export-Clixml “c:\scripts\my_history.xml”
Import-Clixml “c:\scripts\my_history.xml” | Add-History

Enable-PSRemoting
Set-Item WSMan:\localhost\Client\TrustedHosts *
Restart-Service winrm -Force
New-PSSession -ComputerName Server01
Enter-PSSession 2
Enter-PSSession -ComputerName Server02
Exit-PSSession
Get-PSSession | Remove-PSSession
Get-Service -ComputerName Server02
Get-Service -ComputerName Server02 | Where-Object {$_.Name -eq “BITS”}
$Servers = @(“Server01”, “Server02”)

foreach ($Server in $Servers) {

Write-Host “Server: ” $server

Get-Service -ComputerName $server | Where-Object {$_.Name -eq “BITS”}

}

The Most Important PowerShell Parameters
-ErrorAction SilentlyContinue
-MemberType (Get-Member)
-Recurse with Get-ChildItem (Sub-directories)
-Force with Get-ChildItem (Lists hidden files)
-Auto (Adjust the width with Format-Table)
-GroupBy (Collate similar items)
-Filter (Get-WmiObject “Win32_Process”)
-List with Get-WmiObject (Get-Eventlog -List)
-Com (New-Object)
-WhatIf (Test before you commit)
-Debug
-Verbose
-OutBuffer
-ErrorVariable
-WarningAction
-OutVariable
-WarningVariable
-ErrorAction
-Confirm
-WhatIf
-Credential
-Name
-Server
-Force
-InputObject
-PassThru
-AuthType
-Path
-Filter
-UseTransaction
-Exclude
-Include
-Identity
-ComputerName
-Cluster
-Authentication
-Domain
-Partition
-PSPath
-ThrottleLimit
-AsJob
-LiteralPath
-Namespace
-Value
-Description
-Location
-DisplayName
-ArgumentList
-Properties
-Impersonation

4 thoughts on “PowerShell for Lazy Persons

  1. Baby Girl Nursery

    Aw, this was an incredibly good post. Spending some time and actual effort to make a very good article…
    but what can I say… I hesitate a whole lot and never seem to get anything done.

    Reply
    1. tomaszzackiewicz Post author

      Thanks for your advice. I’m still playing with this website. I’m testing the software. It’s a normal way in IT. As to the post… Well, those PowerShell commands, collected on one page, are useful for me. Sometimes I can forget something, and I can look on my website to recollect. I’ll do the same with other IT technologies. There will be various posts on this website, so please do not be surprised.

      Reply
  2. remove programs

    Wow, awesome weblog format! How lengthy have you ever been running a blog for?
    you made running a blog look easy. The overall glance of your web
    site is fantastic, let alone the content!

    Reply
    1. tomaszzackiewicz Post author

      Thanks! Theme: Twenty Twelve. I think it’s the best for me because I need a blog that can accept a lot of text. That’s why I like simple solutions. I’ve been running my blog since a few weeks. Your product seems good, and I wish to test it some day.

      Reply

Leave a comment