http://www.powershellpro.com/powershell-tutorial-introduction/
Launch it from a command prompt with POWERSHELL
Exit with EXIT
Customize a shortcut to point to a home directory
Create a directory C:\scriptsTry these commands:
Click Start and type in POWERSH
Right-drag "Windows PowerShell" to the desktop and drop it there.
Click "Create Shortcut(s) Here"
Right-click the "Windows PowerShell" icon on your desktop and click "Properties"
In the "Start In:" text box, type C:\SCRIPTS
Click OK
Double-click the shortcut to launch PowerShell
get-aclNote:
get-alias
get-command
get-date
Tab Completion
Up-arrow for history list
Case insensivity
F7 for history list
Get-Command shows all commands
Get-Command -Verb Get shows all commands that use the verb "Get"
Get-Command -Noun History shows all commands that use the noun "History"
Get-Help shows help about Get-Help, on one long page
Help shows help about Get-Help, one page at a time
Help * shows all help topics
Get-Command -Noun Service shows all commands that use the noun "Service"
Get-Service shows all services
services.msc works because native Windows commands work from Powershell
Get-Service -name Browser
Stop-Service -name Browser
It fails unless you ran PowerShell as an Administrator
Get-Service -name Browser
Get-Alias shows built-in aliasesNote that ls and dir and gci are all aliases for Get-ChildItem.
Set-ExecutionPolicy Unrestricted -whatif shows what would happenSet-ExecutionPolicy Unrestricted -confirm asks user for confirmationSuspend changes prompt to allow you to execute more commands before confirming, such as Set-ExecutionPolicy and Unrestricted to see what it will do. Exit leaves Suspend mode.
Objects have Properties and Methods.
Get-Service | Get-Member shows Properties and Methods of the "Get-Service" cmdlet
Get-Service | Get-Member -MemberType Property shows Properties of the "Get-Service" cmdlet
Get-Service | Get-Member -MemberType Method shows Methods of the "Get-Service" cmdlet
Notice the Name property.
Get-ChildItem -Path C:\ shows all files and folders in C:\
Get-ChildItem -Path C:\ -Recurse shows all files and folders on the C:\ drive
Get-ChildItem -Path C:\ -Recurse | Where-Object {$_.LastWriteTime -gt "5/1/2011"} shows all files and folders on the C:\ drive that were modified after May 1, 2011
Get-ChildItem -Path C:\users -Recurse | Where-Object {$_.LastWriteTime -gt "5/1/2011"} shows all files and folders in the C:\users folder that were modified after May 1, 2011
Get-Command Format-* shows the four format typesGet-ChildItem C:\Windows | Format-Table outputs a tableGet-ChildItem C:\Windows | Format-Table -AutoSize adjusts column sizesGet-ChildItem C:\Windows | Format-List shows several propertiesGet-ChildItem C:\Windows | Format-List -Property FullName, LastWriteTime shows specified properties
Get-ChildItem | Get-Member shows all properties and methods available (directory must not be empty)
Get-EventLog System | Group-Object eventid | Sort-Object Count -descending sorts event log with most numerous events first
Get-Process | ConvertTo-html displays raw HTML, not much use
Get-Process | ConvertTo-html | out-file "Processes.html" creates an HTML file
Get-Process | Export-CSV Processes.csv makes a CSV file
Last modified: 11-15-2012