Skip to main content

Posts

Showing posts from October, 2012

Export Your Performance Monitor Data to Excel

Updated: 2016MAY04 To clarify when this functionality is available, you can only save the view when you are viewing a Data Collection Set.  The "live" data cannot be saved in this way. Performance Monitor in Windows Server give us the ability to see when our servers are having some issues.  Analyzing that data into something meaningful can be a problem.  You can export your data to Excel so you can better see what your performance data represents.  First collect your data. Right click the graph and select Save Data As . Change the Save as type to Text file (comma delimited)(*.csv) . Give the file a name and save it where you want to store it. Now open that file on a client with Excel installed on it.  By using excel, you will be able to present the data in a more meaningful format.

How to write a string of text in multiple colors in PowerShell

One of the features about PowerShell that drew my attention away from VBScript many years ago was PowerShell’s ability to output information in multiple colors.  When you use Write-Host to display text on the screen, you also get to use the ForegroundColor and BackgroundColor parameters to change the font colors for that line of text. What if you wanted to have a line of text with different colors?  To do this you will need to to use several Write-Host lines.  The problem with that is that you will have your text on multiple lines.  In the Help file for Write-Host , I noticed a parameter NoNewLine that will not put a return at the end of the text.  Your next Write-Host statement will appear on the same line.  Take a look at the code below and the output. Write-host " This is some " -ForegroundColor Green -NoNewline Write-Host " string " -ForegroundColor Red -BackgroundColor DarkRed -NoNewline Write-Host " in different " -ForegroundColo

Use Performance Monitor to Help You Discover Performance Counters for PowerShell

More often than not in my PowerShell classes, I get asked questions about collecting performance information using PowerShell.  One of the big issues that my clients have is how to discover the correct syntax for the performance counters that they want.  The answer is simple, just look at Performance Monitor. We could use the cmdlet Get-Counter –Listset * , but that returns way to much information. Open Performance Monitor and create a Data Collection Set.  (You can find instructions on how to set up a Data Collection Set here .) Collect one sampling of your data and display it in Performance Monitors graph. Right click the graph and select Save Data As . Change the Save as type to Text file (comma delimited)(*.csv) . Give the file a name and save it where you want to store it. Now open that file on a client with Excel installed on it. Take a look at the column headers.  They are the counter data that you want to use in PowerShell. Notice that you can remove the client name

Get the name of a Server using the SID

In class we received audit logs that contained only a SID.  Since we were interested in getting the name of the client associated with that SID, we turned to PowerShell for the answer. The SID actually contains two parts.  A unique code for the domain and then the Relative Identifier (RID) for the the client. This RID is the last portion of the SID and is unique in the network.  Below is an example. S-1-5-21-3400766600-4132462866-2336755051-1149 The RID is the numbers 1149 .  This is what we need to search for in Active Directory.  For a client, use this PowerShell command. Get-ADComputer –Filter * –Properties | Where-Object {$_.SID –like “*1149”} | Select-Object –Property Name, SID The Get-ADComputer cmdlet will retrieve all computer objects in Active Directory. The – Properties parameter will add the SID to the default set of attributes that are returned from the Get-ADComputer cmdlet. The Where-Object cmdlet will filter all the computer objects for one with a SID that ends

North America MCT Summit Day 1

Day one here in Redmond was a lot of fun.  Microsoft Learning briefed us on what is to come and showed us new services and resources that we can use to provide a higher level of service to our clients.  I tagged a few to try out myself.  I also had the opportunity to take 4 MTA exams and provide feedback on them.  I’m happy to say I passed them all. I also got my first look at the 20417 MCAS upgrade exam. It is not one to take lightly. I want to thank June Blender for giving me the opportunity to participate in her session on PowerShell 3.0.  I’m always happy to help.  Now that I finally got some sleep, I’m ready to tackle Day 2.

Automatically create a log of your PowerShell sessions

In my October 3rd article, I wrote about using the PowerShell transcript feature to create a log file of everything you do.  This is a good idea, but it is a manual task.  Here is how you make it automatic.  We are going to use your PowerShell profile.  If you have not yet created a profile, take a look at my blog entry on September 24, 2012. First, create a location to store your transcripts.  This file will contain a lot so it is best to get it organized now. My file is in My Documents in the PowerShell\Transcript folder.  You put yours where it makes sense to you. Now, open your profile.  In PowerShell, type PowerShell_ise $Profile . Enter this set of code in your profile. # -- Automate PowerShell Transcription -- # Create a filename based on a time stamp. $Filename = (( Get-date ).Month).ToString() + " - " + ` (( Get-date ).Day).ToString() + " - " + ` (( Get-date ).Year).ToString() + " - " + ` (( Get-date ).Hour).ToString() + "

How to run GPResult on a remote client with PowerShell

In the past, to run the GPResult command, you would need to either physically visit this client, have the user do it, or use and RDP connection.  In all cases, this will disrupt the user.  First, you need PowerShell remoting enabled on the target machine.  You can do this via Group Policy . Open PowerShell and type this command. Invoke-Command –ScriptBlock {GPResult /r} –ComputerName <ComputerName> Replace <ComputerName> with the name of the target.  Remember, the target needs to be online and accessible to you.

Forcing a remote GPUpdate on a Client

Many times I have had to talk a remote user through a manual refresh of Group Policy.  Depending on the comfort level of the user, this is either a comfortable processes or a highly stressful event…for both of us.  You can use PowerShell V3 to invoke a GPUpdate on a remote client.  You need to get a few items in order first.   1 – Access to the GroupPolicy module.   Your domain controllers have access to the GroupPolicy module. This is installed by default when they became domain controllers  For Windows 8 clients, download RSAT from here . Once you have access to the module, you need to turn it on. Click Start and Type Programs and Features . If you are using Windows 8, you will also need to click Settings . Click Programs and Features Click Turn Windows Features on or off . This will take a few minutes. Expand Remote Server Administration Tools / Feature Administration Tools . Check Group Policy Management Tools. Click OK. 2 – Configure the Firewall to allow Group Policy

Expanding Custom ErrorVariable usage in PowerShell

Using the PowerShell common parameter –ErrorVariable allows you to capture the error that a cmdlet has produced so you can work with it. Take a look at the following code: $Computers = "NotOnline" ForEach ( $Computer in $Computers ) {     Get-WmiObject Win32_OperatingSystem -ComputerName $Computers -ErrorVariable +MyErrors     Get-Service -ComputerName $Computer -ErrorVariable +MyErrors     Get-Content -Path c:\DoesNotExists.txt -ErrorVariable +MyErrors } If we look at the $MyError variable, we receive the same information that is displayed on the screen: $MyErrors Get-Content : Cannot find path 'C:\DoesNotExists.txt' because it does not exist. At line:6 char:5 +      Get-Content -Path c:\DoesNotExists.txt -ErrorVariable MyErrors +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo           : ObjectNotFound: (C:\DoesNotExists.txt:String) [Get-Content]    , ItemNotFoundException     + FullyQualified

How to set a Server Side Autoreply with PowerShell

The question from class was how to set a mailbox to autoreply to the sender.  In this case, if the sender is requesting support, this auto response will let them know that their email has been received.  It turns out this is a simple one liner in PowerShell. The below command is one continuous line.  This needs to be execute in the Exchange Management Console on the Exchange server. Set-MailboxAutoReplyConfiguration –Identity ITHelpdesk –InternalMessage “ Thank you. Your message has been received. A member of the help desk will contact you shortly. ” –AutoReplyState Enabled Below is how it appears in Outlook for the user who sent the request. If you expect email from outside your organization, you can also set an external rule. Set-MailboxAutoReplyConfiguration –Identity ITHelpdesk –InternalMessage “ Thank you. Your message has been received. A member of the help desk will contact you shortly. ” –ExternalMessage “ Thank you. Your message has been received. A member of the

Search for key words in PowerShell help files

One of my students from a PowerShell class a few weeks back was wondering if he could search PowerShell help files for key words and have those words highlighted in the help file.  This week I decided to tackle this one and here are the results. Below is a screen shot of the function Search-Help .  Please take the time to read through the help file.  The code below is presented as a function that can be turned into a module and added to your PowerShell profile. This code is provided as is and without warranty or support. Function Search-Help { [ CmdletBinding (HelpUri = 'http://get-help-jason-yoder.blogspot.com/2012/10/search-help.html' ) ] Param (     # Parameter $Cmdlet     # The name of the parameter that you want to get help on.     [ Parameter (Mandatory = $true ) ] $Cmdlet ,     # Parameter $Words     # The name of the parameter that you want to get help on.         [ Parameter (Mandatory = $true ) ][ String []] $Words ,     # Parameter