Skip to main content

Posts

PowerShell Transcript

Have you ever worked on trying to figure out how to get a specific chuck of data out from deep within an object, only to forget how you did it once you found it. Or maybe you need to back track you steps but the screens veritcle buffer is full so you cannot see what you are doing? Try using PowerShell’s transcript capability. It is very easy to use. Just type Start-Transcript in the shell. It will save the transcript file to your Documents folder. When you are finished, or want to start a new log, just type Stop-Transcript . Below is a quick example. You will not see the Start-Transcript command in the log file because the log file is opened after the command is typed. The ISE does not have the Start-Transcript cmdlet. Here is an article from the Scripting Guy to help you get the same capability in the ISE. ********************** Windows PowerShell transcript start Start time: 20120810103917 Username : Jason-PC\Jason Machine : JASON-PC (Microsoft Windows NT 6.1.7601 Service Pack 1...

How to determine if a client on your network is locked or not.

To be able to do this in your domain will require some setup work.  First off, you need to configure a Group Policy to ensure that the proper events are being audited on your clients.  As with all Group Policy, you must make sure that the policy is scoped to reach your clients, and that you have allowed ample time for the policy to be replicated in your domain, downloaded to the clients, and applied. Note: This will only work for client that are Windows Vista or later. The audit policy to set is: Logon/Logoff Events with the sub category of Other Logon/Logoff Events set to capture Successful events. In your Group Policy, follow these instructions. Expand Computer Configuration \ Policies \ Windows Settings \ Security Settings \ Advanced Audit Policy Configuration \ Audit Policies \ Logon/Logoff Double click Audit Other Logon/Logoff Events Check Configure the following audit events . Check Success Once this policy is applied to your clients, you will now be able to l...

Error when moving from Core to full GUI in Server 2012

If you are installing the full GUI on your Server core 2012 and receive this error, it is an easy fix.   Install-WindowsFeature : The request to add or remove features on the specified server failed. Installation of one or more roles, role services, or features failed. The source files could not be downloaded.   This simply means that your installation files need to be made available to PowerShell to do this.  To correct this, insert your installation media or map a drive to the installation source on your network.  Now add he – Source parameter to your Install-WindowsFeature cmdlet pointing to Windows folder to complete the installation Import-Module ServerManager Imstall-WindowsFeature –IncludeAllSubfeature User-Interfaces-Infr –Source < SourcePath>

Determine if the Exchange Database is Mounted with PowerShell

While delivering a class at the Federal Reserve, I had the opportunity to help out with optimizing a script for use on exchange.  The script needed to check to see if the database is mounted.  The student was able to see it mounted, but could not extract the exact integer value from the data.  Below is how we did it. Get-Counter -Counter ' \MSExchange Active Manager(*)\Database Mounted ' | ForEach-Object { $_ .CounterSamples} | Select-Object -Property InstanceName, CookedValue   The CookedValue is what they were ultimately looking for. 0 means dismounted and 1 means mounted.

Creating a PowerShell Profile

PowerShell has (or may have) a special script that allows you to set up your PowerShell environment when it starts.  This script can run any valid PowerShell cmdlet. This means you can load up your own functions and aliases.  I  want to caution you that if you intend to make scripts that will be used by others, make sure that you do not rely on any functionality in your profile.  If you do, your script will fail when the other user runs it. Your profile may, or may not be there.  If you have not configured it, it may not even be there yet.  To determine if your profile is present, use this PowerShell command. Test-Path $Profile If it comes back True , then you already have a profile.  If not, we first need to create one.  Type this in PowerShell to create your profile. New-Item –path $profile –type file –force     Directory: C:\Users\Jason\Documents\WindowsPowerShell Mode         ...

How to specify the number of decimal places in PowerShell Output

PowerShell does not have any number formatting built into it. For this reason, we have to use a little bit of .NET to make some changes. Let’s say you have the number 45.54321 and you only want to display the first 2 decimal places. Here is the code. $Num = 45.54321 "{0:N2}" -f $Num 45.54 The first zero is an index number (You will see how this works in a minute.) The N tells us what type of data we are formatting. I Borrowed the below chart from this Microsoft article. Name Specifier Description Currency C The value is displayed as currency, using the precision specifier to indicate the number of decimal places to be displayed. Decimal D The value is displayed using the number of digits in the precision specifier; if needed, leading zeroes are added to the beginning of the number. Percentage P The value is multiplied by 100 and displayed as a percentage. The precision specifier indicates the number of decimal places to be displayed. ...

20410 Installing and Configuring Windows Server 2012 is now available for delivery!

  Yesterday, MCTExpert released our fall newsletter announcing our first Windows Server 2012 class that is ready for delivery.  Much effort is being placed into this next round of course development to ensure a level of quality beyond that delivered to us from Microsoft Learning.  As a training center, I invite you to take the Windows Server 2012 classes to a new level by utilizing an instructor who is seriously committed to going the extra mile.  Please contact me at Jason@MCTExpert.com to schedule this, or another other of our classes.