web cast of powershell
TRANSCRIPT
-
7/30/2019 web cast of powershell
1/37
2009 HP Confidential1
2009 HP Confidential
Dung K Hoang
PowerShellFundamentals
-
7/30/2019 web cast of powershell
2/37
2009 HP Confidential2
2 2009 HP Confidential
PowerShell Webinars
Tuesday, February 02, 2010 Thursday, February 04, 2010
PowerShell Fundamentals
Part I
Dung K Hoang PowerShell Fundamentals
Part II
Dung K Hoang
Tuesday, February 09, 2010 Thursday, February 11, 2010
PowerShell - Active Directory Guido Grillenmeier PowerShell - SCVMM - Guido Grillenmeier
Tuesday, February 16, 2010 Thursday, February 18, 2010
PowerShell
Clustering
Aric Bernard PowerShell - Exchange
David Standish/Joel Ricketts/ Pete Petree
Tuesday, February 23, 2010 Thursday, February 25, 2010
PowerShell - Exchange Web Service Kevin Laahs PowerShell - SCOM - Tommy Carron
Tuesday, March 02, 2010 Thursday, March 04, 2010
PowerShell - MOSS 2007/2010 - Veli-Matti Vanamo
/Brian CarterPowerShell - VMware/Hyper-V Steve Fortuna/Ken J Bell
Tuesday, March 09, 2010 Thursday, March 11, 2010
POwerShell - Citrix Workflow Albert Hols Advanced PowerShell Dung K Hoang
Tuesday, March 16, 2010 Thursday, March 18, 2010
PowerShell - WMI SCCM David Lee PowerShell and Office apps David Lee
-
7/30/2019 web cast of powershell
3/37
2009 HP Confidential3
3 2009 HP Confidential
Communities
MentoringCareer Development
Personal Development
For more information, please visithttp://intranet.hp.com/TSG/WW2/professions
This presentation is brought to you by theMicrosoft Profession
KnowledgeSharing
CollaborationCommunity
Events
TrainingDevelopmentCertification
NetworkingRecognition
Access to worldwidecommunity of peers
and mentors
Decide Enroll Participate Grow
http://intranet.hp.com/TSG/WW2/professionshttp://intranet.hp.com/TSG/WW2/professions -
7/30/2019 web cast of powershell
4/37
-
7/30/2019 web cast of powershell
5/37
2009 HP Confidential5
5 2009 HP Confidential
Old World and New World
VBScriptSet listExchange_Mailboxs =GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2").InstancesOf("Exchange_Mailbox")
For Each objExchange_Mailbox in listExchange_Mailboxs
WScript.echo "AssocContentCount = + objExchange_Mailbox.AssocContentCount
WScript.echo " DateDiscoveredAbsentInDS = + objExchange_Mailbox.DateDiscoveredAbsentInDS
WScript.echo " DeletedMessageSizeExtended = + objExchange_Mailbox. DeletedMessageSizeExtended
WScript.echo " LastLoggedOnUserAccount = + objExchange_Mailbox. LastLoggedOnUserAccount
WScript.echo " LastLogoffTime = + objExchange_Mailbox. LastLogoffTime
WScript.echo " LastLogonTime = + objExchange_Mailbox. LastLogonTimeWScript.echo " LegacyDN = + objExchange_Mailbox. LegacyDN
WScript.echo " MailboxDisplayName = + objExchange_Mailbox. MailboxDisplayName
WScript.echo " MailboxGUID = + objExchange_Mailbox. MailboxGUID
WScript.echo " ServerName = + objExchange_Mailbox. ServerName
WScript.echo " Size = + objExchange_Mailbox. Size
WScript.echo " StorageGroupName = + objExchange_Mailbox. StorageGroupName
WScript.echo " StorageLimitInfo = + objExchange_Mailbox. StorageLimitInfo
WScript.echo " StoreName = + objExchange_Mailbox. StoreName
WScript.echo " TotalItems = + objExchange_Mailbox. TotalItems
Next
PowerShell
get-mailboxstatistics server $servername
-
7/30/2019 web cast of powershell
6/37
2009 HP Confidential6
6 2009 HP Confidential
Windows PowerShell
Next generation of interactive shell and scripting environment
Foundation to build GUI management console Equality between command-line tasks and GUI tasks
Extensible PowerShell in Windows Server 2008 R2 components: Cluster- Server Manager
PowerShell in Exchange 2007 SQL 2008 SCOM 2008SCVMM 2008
-
7/30/2019 web cast of powershell
7/37
2009 HP Confidential77 2009 HP Confidential
Duality in PowerShell
Scripting LanguageInteractive Shell
For DevelopersFor Administrators
.NET FrameworkObject-based Shell
-
7/30/2019 web cast of powershell
8/37
2009 HP Confidential88 2009 HP Confidential
PowerShell V1
Released to the Web
Over 3.5 million downloads
in less than 30 months
Windows XP
Windows Vista
Windows Server 2003
Features in
Windows Server 2008
-
7/30/2019 web cast of powershell
9/37
2009 HP Confidential99 2009 HP Confidential
PowerShell V2
Shipped in all Windows Server 2008 R2 EditionsShipped in all Windows 7 Editions
Installed by default
Included in the Windows Management FrameworkReleased to the WEB ( RTW)
http://support.microsoft.com/kb/968929
For Windows XP / Windows Server 2003 and above
http://support.microsoft.com/kb/968929http://support.microsoft.com/kb/968929 -
7/30/2019 web cast of powershell
10/37
2009 HP Confidential1010 2009 HP Confidential
PowerShell V1 and V2
129 PowerrShell cmdlets
COM
WMIADSI
ADO
XML
.NET Native commands and text
processing
244 PowerShell cmdlets
Improved ADSI, WMI,COM, XML, ADO,text processing
Native .Net Languages C#, VB.NET, F#
Pinvoke to Win32
WS-MGMT Web Services
Cmdlets for Windowscomponents
V1 V2
-
7/30/2019 web cast of powershell
11/37
-
7/30/2019 web cast of powershell
12/37
2009 HP Confidential1212 2009 HP Confidential
Windows Components / Server Applicationswith PowerShell
Exchange Server WindowsDiagnostics ServerManager SQL Server ActiveDirectory FailoverClustering SC Operations Manager WindowsBackup ServerMigration SC Virtual Machine
Manager BestPracticesAnalyzer ADRightsManagementServices Essential Business Server InternetInformationServices BackgroundIntelligentTransferService SC Data Protection Manager
NetworkLoadBalancing RemoteDesktopServices SharePoint 2010 GroupPolicyAppLocker HighPerformance Computing WS-Management WMI Message Queuing
-
7/30/2019 web cast of powershell
13/37
2009 HP Confidential1313 2009 HP Confidential
Books on PowerShell
Now available inJapanese
German
French
More
2007 2008
http://blogs.msdn.com/blogfiles/powershell/WindowsLiveWriter/TowerofPowerPart2_887B/001_1.jpghttp://www.amazon.com/Microsoft-Windows-PowerShell-Step/dp/0735623953/ref=sr_1_1?ie=UTF8&s=books&qid=1262822631&sr=8-1 -
7/30/2019 web cast of powershell
14/37
2009 HP Confidential1414 2009 HP Confidential
Books on PowerShell
Recommended books for beginners
Authorative book for advanced users
http://www.amazon.com/Windows-PowerShell-TM-Scripting-Guide/dp/0735622795/ref=sr_1_6?ie=UTF8&s=books&qid=1262822631&sr=8-6http://www.amazon.com/Microsoft-Windows-PowerShell-Step/dp/0735623953/ref=sr_1_1?ie=UTF8&s=books&qid=1262822631&sr=8-1 -
7/30/2019 web cast of powershell
15/37
2009 HP Confidential1515 2009 HP Confidential
Resources to Learn PowerShell
Windows PowerShell is Powerful Automation! 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
HP Knowledge Briefs ~91 articles!
Code and Script repository
List of PowerShell resources
http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/PowerShellV2forDevelopers/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/PowerShell/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell2/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell3/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell4/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell5/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell6http://kb.know.hp.com/http://blogs.hp.com/msprofession/2010/02/03/code-and-script-repository/http://blogs.hp.com/msprofession/2010/01/25/windows-powershell-resources/http://blogs.hp.com/msprofession/2010/01/25/windows-powershell-resources/http://blogs.hp.com/msprofession/2010/02/03/code-and-script-repository/http://kb.know.hp.com/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell6http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell5/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell4/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell3/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/VPowerShell2/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/PowerShell/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/PowerShellV2forDevelopers/http://channel9.msdn.com/learn/courses/WindowsServer2008R2/PowerShell/ -
7/30/2019 web cast of powershell
16/37
2009 HP Confidential16 2009 HP Confidential16
Learning the Basics
-
7/30/2019 web cast of powershell
17/37
2009 HP Confidential1717 2009 HP Confidential
PowerShell Fundamentals
Use for expansionPipelining
Alias
Four (4) commands to learn PowerShell!Help
Get-Command
Get-MemberGet-PSDrive
Demo
-
7/30/2019 web cast of powershell
18/37
2009 HP Confidential1818 2009 HP Confidential
PowerShell Cmdlets Syntax
-
7/30/2019 web cast of powershell
19/37
2009 HP Confidential1919 2009 HP Confidential
Outputting - Formatting
Writing to Write-host Write-file
Write-output
Sending to.. Out-NULL
Out-File
Out-Printer
Formatting with Format-table
Format-list
Dont know the differences?
1. Try it!
2. Use Help!
3. Look at examples in thehelp command!
Help write-* , out-*, format-*Demo
-
7/30/2019 web cast of powershell
20/37
2009 HP Confidential2020 2009 HP Confidential
Variables
Name $ + $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
Help about_Variables
-
7/30/2019 web cast of powershell
21/37
2009 HP Confidential2121 2009 HP Confidential
Variable Name 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
$Args Used in creating functions that require parameters
$Error If an error occurred, the object is saved in the $error PowerShell variable
$foreach Refers to the enumerator in a foreach loop.$HOME The user's home directory; set to %HOMEDRIVE%\%HOMEPATH%
$Input Input piped to a function or code block
$Match A hash table consisting of items found by thematch operator.
$MyInvocation Information about the currently script or command-line
$Host Information about the currently executing host
$LastExitCode The exit code of the last native application to run$true Boolean TRUE
$false Boolean FALSE
$null A null object
$OFSOutput Field Separator, used when converting an array to a string.By default, this is set to the space character.
$ShellIDThe identifier for the shell. This value is used by the shell to determine theExecutionPolicy and what profiles are run at startup.
$StackTrace contains detailed stack trace information about the last error
PowerShell $ Variables
C ll ti A H h T bl
-
7/30/2019 web cast of powershell
22/37
2009 HP Confidential2222 2009 HP Confidential
Collections : Arrays Hash TablesArrays
$MyLuckyNumbers = 1,25,32,49 $MyRange= 1..100 + -100..-1 $List= @() $List += 2 ; $List +=5
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_ArraysHelp about_Hash_TablesDemo
-
7/30/2019 web cast of powershell
23/37
2009 HP Confidential2323 2009 HP Confidential
OperatorsTypes
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
Special operators & = 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
Help about_Operators
-
7/30/2019 web cast of powershell
24/37
2009 HP Confidential2424 2009 HP Confidential
Flow control
Help about_if, about_for, about_foreach, about_switch
If / ElseWhile loop
Do / while loop
For loop
Foreach loop
Switch
-
7/30/2019 web cast of powershell
25/37
2009 HP Confidential2525 2009 HP Confidential
Filtering
Help where, help Select
Where-objectSelect-Object
Demo
-
7/30/2019 web cast of powershell
26/37
2009 HP Confidential2626 2009 HP Confidential
Alias
Help about_alias
Name Cmdlet
Dir , ls Get-childitem
Cd , md , rd Set-Location, New-Item, Remove-Item
Ft fl Format-Table , Format-List
Where Where-object
Foreach, % Foreach-object
Gal Get-alias
.
-
7/30/2019 web cast of powershell
27/37
2009 HP Confidential2727 2009 HP Confidential
Functions & Scripts
ScriptsText file with extension .ps1
Script Block
{ get-process ; $i+=32}
$Args variableBuilt-in variable
Auto populate with objects containing values passed to thescript/function
Param StatementTo declare formal parameters
Param ([string]$server=localhost, [int]Max=10)
Help about_functions, about_scripts
-
7/30/2019 web cast of powershell
28/37
2009 HP Confidential28 2009 HP Confidential28
Advanced Techniques
in PowerShell
-
7/30/2019 web cast of powershell
29/37
2009 HP Confidential2929 2009 HP Confidential
Get-Member Your Best Friend!
PowerShell emits objects
Get-Member lists Properties and Methods of
objects
Useful for exploring other properties of objectsGet-Member .vs. Format-Table
Help Get-MemberDemo
-
7/30/2019 web cast of powershell
30/37
2009 HP Confidential3030 2009 HP Confidential
PSDrive
Exposes system data as file system drive
Administrator navigates through system data using
standard file system commands : cd ls dir-
mkdir.
PSDrive Usage
Alias: List of PowerShell aliases
Function: All available functions for the current session
Cert: Access to the certificates store
Env: List of system/user environment variables
Variable: List of declared variables
HKCU: HKLM: Access to registry
Help *PSDRIVE*Demo
-
7/30/2019 web cast of powershell
31/37
2009 HP Confidential3131 2009 HP Confidential
Working with Strings
String Properties / Methods
Import-CSV ConvertTo-CSV
Select-String
Here-String or @String expansion
Numeric format strings
{0:D3} f 2
Help *String* - help * csv*Demo
-
7/30/2019 web cast of powershell
32/37
2009 HP Confidential3232 2009 HP Confidential
Working with Files
Listing Files
Reading from / Writing to files
Search text in files select-string
Help *content*Demo
-
7/30/2019 web cast of powershell
33/37
2009 HP Confidential3333 2009 HP Confidential
Working with Date/Time
DateTime object
Fomatting
{0:F}-f [DateTime]01/12/1975
Measure time TimeSpan object
Demo
-
7/30/2019 web cast of powershell
34/37
2009 HP Confidential3434 2009 HP Confidential
Working with Events - ACL
Get-WinEvent
Get-EventLog
Get-ACL / Set-ACL
Demo
-
7/30/2019 web cast of powershell
35/37
2009 HP Confidential3535 2009 HP Confidential
Summary
Windows PowerShell is both an interactiveshell and a scripting language
Most Windows components and server
applications ship with their own PowerShell
cmdlets
Windows PowerShell enables automation of
admin processes and reduces human error in
operations
ConvergedInfrastructure
Virtualized Resilient Orchestrated Optimized Modular
-
7/30/2019 web cast of powershell
36/37
2009 HP Confidential3636 2009 HP Confidential
More Resources.
TechNet Script Center
PowerShell Code Repository
MS Instructor-Led PowerShell training
HP Forums: PowerShell
MS Professions Webinars!
N t P Sh ll W bi
http://technet.microsoft.com/en-us/scriptcenter/default.aspxhttp://poshcode.org/http://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://forums.know.hp.com/Forums/postlist.php?Cat=0&Board=powershell&page=0http://forums.know.hp.com/Forums/postlist.php?Cat=0&Board=powershell&page=0http://forums.know.hp.com/Forums/postlist.php?Cat=0&Board=powershell&page=0http://forums.know.hp.com/Forums/postlist.php?Cat=0&Board=powershell&page=0http://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://www.microsoft.com/learning/en/us/course.aspx?ID=6434A&locale=en-ushttp://poshcode.org/http://poshcode.org/http://poshcode.org/http://technet.microsoft.com/en-us/scriptcenter/default.aspx -
7/30/2019 web cast of powershell
37/37
2009 HP Confidential3737 2009 HP Confidential
Tuesday, February 02, 2010 Thursday, February 04, 2010
PowerShell Fundamentals
Part I
Dung K Hoang PowerShell Fundamentals
Part II
Dung K Hoang
Tuesday, February 09, 2010 Thursday, February 11, 2010
PowerShell - Active Directory Guido Grillenmeier PowerShell - SCVMM - Guido Grillenmeier
Tuesday, February 16, 2010 Thursday, February 18, 2010
PowerShell Clustering Aric Bernard PowerShell - Exchange David Standish/Joel Ricketts/ Pete Petree
Tuesday, February 23, 2010 Thursday, February 25, 2010
PowerShell - Exchange Web Service Kevin Laahs PowerShell - SCOM - Tommy Carron
Tuesday, March 02, 2010 Thursday, March 04, 2010
PowerShell - MOSS 2007/2010 - Veli-Matti Vanamo/Brian Carter
PowerShell - VMware/Hyper-V Steve Fortuna/Ken J Bell
Tuesday, March 09, 2010 Thursday, March 11, 2010
POwerShell - Citrix Workflow Albert Hols Advanced PowerShell Dung K Hoang
Tuesday, March 16, 2010 Thursday, March 18, 2010
Next PowerShell Webinars