Web Cast of Powershell
Web Cast of Powershell
Web Cast of Powershell
PowerShell Webinars
Tuesday, February 02, 2010 PowerShell Fundamentals Part I Dung K Hoang Thursday, February 04, 2010 PowerShell Fundamentals Part II Dung K Hoang
Tuesday, March 02, 2010 PowerShell - MOSS 2007/2010 - Veli-Matti Vanamo /Brian Carter
Thursday, March 18, 2010 PowerShell and Office apps David Lee
Communities
Knowledge Sharing Collaboration Community Events
Personal Development
Training Development Certification
Decide
3 2009 HP Confidential
Enroll
Participate
Grow
of PowerShell
PowerShell 101
Key Takeaways
Learn
Non Goals
Full
training on PowerShell
2009 HP Confidential
= + objExchange_Mailbox. LastLogonTime
WScript.echo " LegacyDN = + objExchange_Mailbox. LegacyDN WScript.echo " MailboxDisplayName = + objExchange_Mailbox. MailboxDisplayName WScript.echo " MailboxGUID WScript.echo " ServerName WScript.echo " Size WScript.echo " StorageGroupName WScript.echo " StorageLimitInfo WScript.echo " StoreName WScript.echo " TotalItems Next = + objExchange_Mailbox. MailboxGUID = + objExchange_Mailbox. ServerName = + objExchange_Mailbox. Size = + objExchange_Mailbox. StorageGroupName = + objExchange_Mailbox. StorageLimitInfo = + objExchange_Mailbox. StoreName = + objExchange_Mailbox. TotalItems
PowerShell
5
Windows PowerShell
Next generation of interactive shell and scripting environment Foundation to build GUI management console
Extensible
PowerShell in Windows Server 2008 R2 components: Cluster- Server Manager PowerShell in Exchange 2007 SQL 2008 SCOM 2008 SCVMM 2008
2009 HP Confidential
Duality in PowerShell
For Administrators For Developers
Object-based Shell
.NET Framework
Interactive Shell
7 2009 HP Confidential
Scripting Language
PowerShell V1
Released to the Web
2009 HP Confidential
PowerShell V2
Shipped in all Windows Server 2008 R2 Editions
Installed by default
to the WEB ( RTW) http://support.microsoft.com/kb/968929 Windows XP / Windows Server 2003 and above
2009 HP Confidential
PowerShell V1 and V2
V1
129 PowerrShell cmdlets COM WMI ADSI ADO XML .NET Native commands and text processing
10 2009 HP Confidential
V2
244 PowerShell cmdlets Improved ADSI, WMI, COM, XML, ADO, text processing Native .Net Languages
C#,
New Cmdlets in V2
Remoting:
Invoke-Command Enter-PSSession Exit-PSSession Export-PSSession Get-PSSession Import-PSSession New-PSSession Remove-PSSession
Transactions:
Complete-Transaction Get-Transaction Start-Transaction Undo-Transaction Use-Transaction
WMI:
Invoke-WMIMethod Register-WMIEvent Remove-WMIObject Set-WMIInstance
Debugging:
Disable-PSBreakpoint Enable-PSBreakpoint Get-PSBreakpoint Get-PSCallStack Remove-PSBreakpoint Set-PSBreakpoint
More Cmdlets:
Clear-History Get-Random Out-GridView Set-StrictMode Update-List Debug-Process Start-Process Wait-Process
Converting Types:
Add-Type ConvertFrom-Csv
ConvertTo-Csv
ConvertFrom-StringData ConvertTo-Xml
Eventing:
Get-EventSubscriber Get-Event New-Event Register-EngineEvent Register-ObjectEvent Remove-Event Unregister-Event Wait-Event
Computer:
Script Internationalization:
Import-LocalizedData
Modules:
Get-Module Import-Module New-Module
11 2009 HP Confidential Remove-Module
Background Jobs:
Get-Job Receive-Job Remove-Job Start-Job Stop-Job Wait-Job
Add-Computer Checkpoint-Computer Remove-Computer Restart-Computer Restore-Computer Stop-Computer Disable-ComputerRestore Enable-ComputerRestore Get-ComputerRestorePoint Reset-ComputerMachinePassword Test-ComputerSecureChannel
Export-ModuleMember
Books on PowerShell
Now available in
Japanese German French More
13
2009 HP Confidential
2007
2008
Books on PowerShell
Recommended books for beginners
14
2009 HP Confidential
Powershell V2 for Developers Windows PowerShell is Powerful Automation! Variables, Types, and Operators Arrays Conditionals, Collections, and Loops Create Object Cmdlets Remote Sessions Advanced Remote Sessions
16
2009 HP Confidential
PowerShell Fundamentals
Use <TAB> for expansion Pipelining Alias Four (4) commands to learn PowerShell!
Help
Get-Command Get-Member Get-PSDrive
Demo
17
2009 HP Confidential
18
2009 HP Confidential
Outputting - Formatting
Writing to
Write-host Write-file Write-output
Dont know the differences?
1. Try it! 2. Use Help!
Sending to..
Out-NULL Out-File Out-Printer
Formatting with
Format-table Format-list
Demo
19
2009 HP Confidential
Variables
Name
$ + <Name of the variable> $a , $1_Password_for_you
Scope
$local:Myresult $script:ListofElements $global:username
Type
All
variables are objects: .NET objects Best match of the type based on what you have
20 2009 HP Confidential
Help about_Variables
PowerShell $ Variables
Variable Name $_ $^ $$ $? $Args $Error $foreach $HOME $Input $Match $MyInvocation $Host $LastExitCode $true $false $null $OFS $ShellID
21
Description The current pipeline object; used in script blocks, filters, the process clause of functions, where-object, foreach-object and switch contains the first token of the last line input into the shell contains the last token of last line input into the shell Contains the success/fail status of the last statement Used in creating functions that require parameters If an error occurred, the object is saved in the $error PowerShell variable Refers to the enumerator in a foreach loop. The user's home directory; set to %HOMEDRIVE%\%HOMEPATH% Input piped to a function or code block A hash table consisting of items found by the match operator. Information about the currently script or command-line Information about the currently executing host The exit code of the last native application to run Boolean TRUE Boolean FALSE A null object Output Field Separator, used when converting an array to a string. By default, this is set to the space character. The identifier for the shell. This value is used by the shell to determine the ExecutionPolicy and what profiles are run at startup. contains detailed stack trace information about the last error
$StackTrace
2009 HP Confidential
Hash Tables
$Months = @ { Jan= 1; Feb=2 ; Mar=3}
$Months.Jan , $Months.Feb $aHash = @{} $aHash[Expert] = You! $aHash[13] = Prime $aHash[pi] = 3.1415
Help about_Arrays Help about_Hash_Tables
Demo
22
2009 HP Confidential
Operators
Types Arithmetic Assignment Comparison +-*/% = += -= *= /= %= ++ --eq -ceq -ieq -ne -cne -ine -gt -cgt -igt -ge -cge -ige -lt -clt -ilt -le -cle -ile -contains -nocontains -match -nomatch -like -notlike -and -or -xor -not -band -bor -bxor -bnot & = call operator . = Property deference operator . = Dot sourcing operator :: = Static member operator .. = Range operator -f = format operator -split , -match , replace = string operator $( ) = Subexpression operator @( ) = Array subexpression operator
Special operators
23
2009 HP Confidential
Help about_Operators
Flow control
If / Else
While loop
Do / while loop For loop Foreach loop Switch
24
2009 HP Confidential
Filtering
Where-object
Select-Object
Demo
25
2009 HP Confidential
Alias
Name Dir , ls Cd , md , rd Cmdlet Get-childitem Set-Location, New-Item, Remove-Item
Ft fl
Where Foreach, % Gal .
Format-Table , Format-List
Where-object Foreach-object Get-alias
26
2009 HP Confidential
Help about_alias
Script Block
{ get-process ; $i+=32} $Args variable
Built-in
variable Auto populate with objects containing values passed to the script/function
Param Statement
To
27
2009 HP Confidential
28
2009 HP Confidential
Demo
29
2009 HP Confidential
Help Get-Member
PSDrive
Exposes system data as file system drive Administrator navigates through system data using standard file system commands : cd ls dirmkdir.
PSDrive Alias: Function: Cert: Env: Usage List of PowerShell aliases All available functions for the current session Access to the certificates store List of system/user environment variables
Variable:
HKCU: HKLM:
Demo
30
2009 HP Confidential
Help *PSDRIVE*
String expansion
Numeric format strings {0:D3} f 2
Demo
31
2009 HP Confidential
Demo
32
2009 HP Confidential
Help *content*
Demo
33
2009 HP Confidential
Demo
34
2009 HP Confidential
Summary
Windows PowerShell is both an interactive shell and a scripting language Most Windows components and server applications ship with their own PowerShell Converged Infrastructure cmdlets Windows PowerShell enables automation of admin processes and reduces human error in Virtualized operations Resilient Orchestrated Optimized Modular
35
2009 HP Confidential
More Resources.
TechNet Script Center PowerShell Code Repository
Tuesday, March 02, 2010 PowerShell - MOSS 2007/2010 - Veli-Matti Vanamo /Brian Carter
Thursday, March 18, 2010 PowerShell and Office apps David Lee