Last night we had some technical difficulties with our user group and getting the broadcast and the speaker setup and going. So we had to make up something good to talk about in the user group.
So what we ended up doing was what I like to call a round table. In this discussion everyone relayed some of their successes with PowerShell. This article is just a “glimpse’ of some of the tidbits I was able to capture during the meeting.
If you are anything like me you like things that you can do to help you remember a command you last typed or you like to bring back a command from history and modify it slightly and try again. One of the users last night showed us this wonder full trick in powershell the #(tab).
The best way to show this feature is to tell you to use the Get-History cmdlet in PowerShell to show your last few Items you’ve typed.
PSGit:\> Get-History Id CommandLine -- ----------- 1 $env:COMPUTERNAME 2 h 3 $env:PSModulePath 4 $env:PSModulePath -split ';' 5 h 6 ($env:PSModulePath -split ';') 7 ($env:PSModulePath -split ';') 8 ($env:PSModulePath -split ';') 9 h 10 get-process 11 h 12 get-service
I only show the history so there is context around what this little gem of a tip does. if I type #PS and then hit tab I’ll get each item from history that contains PS. Demonstrated below:
Now for another tip that I found useful as well. Have you ever wanted to create a variable and have the output of the variable on the screen as well. This can be done with Tee-Object but there is a much shorter method that one of the users in the AZ Powershell User group demonstrated:
PSGit:\> ($var = ($env:PSModulePath -split ';')) C:\Users\crshn\Documents\WindowsPowerShell\Modules PSGit:\> $var C:\Users\crshn\Documents\WindowsPowerShell\Modules
Simply enclose your command in parens and you get the output in your variable and to your screen.
We had a great discussion about this post Merging hashtables. This spurned a discussion on a very cool means to copy your object intact to another object. The participant in the user group informed me that he’d share his code with me. When I receive it I’ll add to this Post.
Lastly another user demonstrated how they use data from the perfmon reliability counters that every windows machine has. you can view those reliability counters through a simple command at your prompt:
Turns out these counters are part of WMI and you could drill into these to help you with diagnosing problems in your infrastructure through Powershell and WMI.
Here is a post from Richard Siddaway on how he used some of the items in the class that this provides:
It was a very fun Users group. If you are online or in Phoenix area Drop by and we’ll entertain you with a speaker or any of the great folks that attend.