Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-Counter cmdlet.
What can I do with it?
Collect real-time performance counter data directly from local or remote computers.
Examples:
Create a list of performance counters available to query in the Memory counter
(Get-Counter -listset memory).paths
Tip: To find a list of available top-level counters for which you could substitute in for memory in the above example you could type this set of commands:
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Send-MailMessage cmdlet.
What can I do with it?
Send an email message using a specific SMTP server, from within a script or at the commaned line.
Example:
Send-MailMessage -to “Joe Bloggs
[email protected]” -from “Jane Smith
[email protected]” -subject “Reporting Document” -body “Here’s the document you wanted” -Attachment “C:\Report.doc” -smtpServer smtp.test.local
How could I have done this in PowerShell 1.
This is the first of a series looking at new cmdlets available in PowerShell 2.0. We begin by looking at the Get-Random cmdlet.
What can I do with it?
With Get-Random you can either generate a random number, or randomly select objects from a collection.
Examples:
Generate a random number between 1 and 100.
Get-Random -Minimum 1 -Maximum 101
Select a random object from a collection
$users = ‘Rod’,‘Jane’,‘Freddy’ Get-Random $users
I have been lucky enough to be invited to run a PowerCLI pre-show workshop before the main event of the next London VMUG on 24th November. A couple of VMUG’s back Alan Renouf ran a similar session on how to get started with PowerCLI. I thought this time I would move things one step on so the kind of topics I am likely to cover are reporting scripts and how you can make practical use of them, oneliners to get you great information and take a look at the VESI.
When I got into PowerShell a couple of years back one of the first resources I discovered was the PowerScripting podcast, at the time just featuring Jonathan Walz (later to be joined by Hal Rottenberg). It was great to find some other people just as enthusiastic about this new technology as I was and also a really good learning tool with loads of resources for getting started. I think I caught up with about the first 20 episodes during a single month and my wife was forever asking me why I was always listening to “those two American guys again….
I regularly recommend and often refer to this document my good friend Alan Renouf put together Quick Reference Guide for PowerCLI. It is really handy guide to pin up by your desk when you need to remind yourself of a cmdlet and maybe one of the most common usages for it.
I’ve been spending a lot of time recently checking out the PowerShell cmdlets for Active Directory in Windows Server 2008 R2 and they have also AD PowerShell Quick Reference Guide together.
Back in March this year I saw a presentation by James O’Neill and Richard Siddaway about some of the new PowerShell features in Windows Server 2008 R2, in particular Active Directory. I was fascinated by the new ‘Recycle Bin’ feature, which is enabled via PowerShell, and could instantly see that this would be a great and long overdue new feature. I am not alone in this; when Mark Minasi recently appeared on the Run As Radio podcast he said the AD Recycle Bin was the standout feature of the whole Server 2008 R2 release, not just the Active Directory part.
A while back I needed to confirm what level of BIOS firmware a bunch of ESX hosts were at. Unfortunately I ran out of time to look properly, but today I discovered how to do it whilst looking through the VMware SDK for something else. Turns out it is very simple:
$VMHost = Get-VMHost ‘Server01’ | Get-View $VMHost.Hardware.BiosInfo
This will give you results along the lines:
BiosVersion ReleaseDate DynamicType DynamicProperty ———– ———– ———– ————— 2.
More stats for my capacity report, this time I want to know on a typical day in the month what is the average CPU and memory use like across my hosts and clusters. Note: this post is not aimed at troubleshooting performance issues, rather at a high level gives me a reasonable idea of the CPU and memory use in each cluster during peak and non-peak hours. By running this each month I can look at possible trends and where extra resource may be required.
More stats for my capacity report, this time numbers of VM’s in total in Virtual Center and average per host in each cluster. Obviously performance is not based on the numbers of VM’s per host, but its an interesting figure to keep track of.
Connect-VIServer virtualcenter | Out-Null
Total number of hosts $TotalVMHosts = Get-VMHost $TotalVMHostsCount = $TotalVMHosts.count Write-Host “There are $TotalVMHostsCount Hosts in $DefaultVIServer” # Total number of guests $TotalVMs = Get-VM $TotalVMsCount = $TotalVMs.