Title: PowerShell for Admins
1 PowerShell for Admins
http//bp0.blogger.com/_O4XKqIP_aWE/Rsq24YoLl4I/AA
AAAAAAALo/oumPQqLvCnI/s1600-h/PowerShell.jpg
- IgorShare Consulting (www.igorshare.com/blog)
- Presenter Igor
Moochnick
2What is PowerShell?
- New Command Prompt?
- No it is a prompt to .NET framework and
scripting engine for your applications - Commands emit objects (Object piping) great
feature - Bunch of tutorials - http//www.powershellpro.com/
powershell-tutorial-introduction/powershell-functi
ons-filters/
3Discovering PowerShell
- PowerShell provides a discoverable environment.
If you dont know something or do not remember
browse around - Most of the commands support wildcards
Get-Help (help) Get-Command (gcm) Get-PSDrive
(gdr) Get-Member (gm)
PS C\gt get-command snapin
4Commands, functions and scripts
- Create and execute scripts and functions
Function Add (intx 0, inty 0)
write-host (x y) PS C\gt Add 10 212
5Calling into .NET framework
- Use .NET types in your scripts
- Call into .NET directly
PS C\gt echo (DateTimeNow)
PS C\gt System.Reflection.Assembly
LoadWithPartialName("System.Windows.Forms"
) PS C\gt System.Windows.Forms.MessageBoxShow(
"Hello)
6Cmdlet Demo
- Code
- build class library
- Registration
- Installutil ltsnapin.dllgt
- Add-PSSnapin ltSnapinNamegt
- Save settings
- Export-console consoleSnapshot
- Execution
- Debugging
- PowerShell PSConsoleFile consoleSnapshot.psc1
7Cmdlets
- PSSnapin (subclass)
- Default registers all Cmdlets
- CustomPSSnapin register specific Cmdlets
- Parameters and Parameter Sets
- Begin/End/StopProcessing
- ProcessRecord
- WriteObject and WriteError
8Pipeline object flow
Input
Output
Cmdlet 1
Cmdlet 2
0
1
2
3
ProcessRecord Call
4
5
Object Injection
6
Object Replacement
7
8
9
Object Cancelation
9Advanced Scripting (PoSH 2.0)
function Get-Total ( Stringproperty (throw
"Property Required"), stringformatString
"Total 1 0" ) Begin total
0 Process total
_.property End formatString
-f total,property
10Debugging in PowerShell
- Debugging and Tracing
- Debug
- Verbose
- Error Handling
- ErrorAction
- ErrorVariable
- Conditional
- Whatif
- Confirm
- Pipelines
- Output your data to a file or other command
11Providers (and Drives)
- Types of providers
- Basic provider
- Drive provider
- Item provider
- Container provider
- Navigation provider
- Content provider
- Property provider
- Default providers
- Alias
- Certificate
- Environment
- FileSystem
- Function
- Providers
- Registry
- Variable
12PASH PoSH bash(http//pash.sourceforge.net)
- Announcement of PowerShell open source
reimplementation - public project
13Pash PowerShell everywhere
14Conclusion
- Think outside of the BOX !!!
15Helpful Links
- Windows PowerShell Team blog http//blogs.msdn.com
/PowerShell - Windows PowerShell ScriptCenterhttp//www.microso
ft.com/technet/scriptcenter/hubs/msh.mspx - Pash - Public Projecthttp//pash.sourceforge.net
- E-mail igor_at_igorshare.com
- Blog http//igorshare.wordpress.com/
- Home Page http//www.igorshare.com/
16Blogroll
- Live PowerShell With Karl Prosser
(http//karlprosser.com/coder/) - The PowerShell Guy (http//thepowershellguy.com/)
- Creating a Windows PowerShell CmdLet using the
Visual Studio Windows PowerShell Templates
(http//blogs.msdn.com/daiken/archive/2007/02/07/c
reating-a-windows-powershell-cmdlet-using-the-visu
al-studio-windows-powershell-templates.aspx) - PowerTab from The PowerShell Guy
(http//thepowershellguy.com/blogs/posh/pages/powe
rtab.aspx)