Archive

Posts Tagged ‘PowerShell’

Changelog: New-SignedScript

This is the changelog page for New-SignedScript. You will find a complete list of released versions, their dates, and the features and issues addressed in each. Please refer to the script’s main page for more information including download links, installation details, and more.

v1.1 – 06-10-2012

  1. Better handling when there is more than one code signing cert. Script now finds the first valid code signing cert and uses that.
  2. Better validation that the script is successfully signed

v1.0 – 09-20-2012

  1. Initial version
Categories: PowerShell Tags: , ,

Script: Get-CsFederatedConversationDetails.ps1 – See Stats About Conversations With Specific Federated Domains

May 13, 2014 8 comments

Lync 2013 logo 128x128Description

Richard Schwendiman, PFE at Microsoft, came up with a great SQL query that you could plug into SQL Server Management Studio to see time & date info for conversations with federated or PIC domains. In Richard’s case, he used the aol.com PIC domain. Since PIC federation with AOL and Yahoo is ending next month, I thought this was great timing on Richard’s part. But sometimes, Lync admins can’t login to SQL servers to run queries due to security policy. Plus, the query is something you’d have to keep handy and edit accordingly each time you wanted to get data. So I figured – hey, why not whip up a quick script to allow an admin to query SQL for this data, allowing for any domain and time frame to be specified? Poof – out comes my script.

This script will query a specific SQL server for information about a specific federated SIP domain. The domain does NOT need to be in the allowed domains list if you’re open federating. Any SIP domain name works. You can specify a start date/time in the yyyy-MM-dd format, such as 2014-05-13 using the -TimeSpan parameter. Or, you can use some handy ranges I’ve included, including LastWeek (the last 7 days), Last30Days, Last year (last 365 days), FirstOfYear or ThisYear (since Jan. 1), FirstOfMonth or ThisMonth (since the 1st of the month), FirstOfWeek or ThisWeek (since Sunday). Optionally, you can specify an end date/time in the yyyy-MM-dd format. This script will default to FirstOfYear with no end date, and aol.com for the domain. As we see below, only the SQL server holding the LcsCDR database is queried.

aol3

Now, from this output, we see that there is not a lot of communications with people on AOL since the first of the year. The upcoming change should have very little impact.

If you’re using a named instance in SQL, you can specify it as well.

The script outputs a full object, just like other cmdlets, so you can pipe it to other commands to alter the display, including sorting, or my favorite, Out-GridView, as well as outputting to files such as .csv.

Hopefully, this tool will make life a little easier in digging out data.

Syntax

Get-CsFederatedConversationDetails.ps1 [[-SqlServer] ] [[-SqlInstance] ] [[-SipDomain] ] [[-TimeSpan] <object>] [[-EndDate] <object>] [-WhatIf ] [-Confirm ] [<commonparameters>]</commonparameters></object>

Installation

Execution Policy: Third-party PowerShell scripts may require that the PowerShell Execution Policy be set to either AllSigned, RemoteSigned, or Unrestricted. The default is Restricted, which prevents scripts – even code signed scripts – from running. For more information about setting your Execution Policy, see Using the Set-ExecutionPolicy Cmdlet.

Assumptions

None

Download

v1.0 – 05-13-2014 – Get-CsFederatedConversationDetails.v1.0.zip

Changelog

See the changelog for information on what’s changed/included in each version.

 

Changelog: Get-CsFederatedConversationDetails.ps1

This is the changelog page for Get-CsFederatedConversationDetails.ps1. You will find a complete list of released versions, their dates, and the features and issues addressed in each. Please refer to the script’s main page for more information including download links, installation details, and more.

v1.0 – 05-13-2014

  1. Initial version

New Syntax Highlighting and Auto-Complete Files for UltraEdit includes PowerShell v4, AD, Lync 2013, and Exchange 2013

March 12, 2014 Leave a comment

Syntax highlighting

Updated the wordfile a little bit. This one includes all previous functions as well as the following:

  1. PowerShell v4 cmdlets (the ones available when you open a new v4 session).
  2. Exchange 2013 SP1 cmdlets
  3. Lync 2013 cmdlets
  4. Active Directory cmdlets

That adds up to 2834 cmdlets/functions that get syntax highlighting on top of the 137 aliases that are also in the file. The file also has variable highlighting, as well as operators and comp operators highlighting.

Formatting changes include the following:

  1. code folding for (), so your long param() blocks can now be collapsed/expanded.
  2. code folding for region/endregion. This mimics the behavior of ISE.

If you’d like to change the colors and/or fonts used for highlighting, go to View>Themes>Manage Themes, as the styling in the wordfile is ignored starting with v20 of UltraEdit.

manage themes

As with all other wordfiles, they are stored in “%appdata%\IDMComp\UltraEdit\Wordfiles\”, unless you change the path in Advanced>Configuration>Editor Display>Syntax Highlighting.

wordfile path

You can optionally set the “Highlight new file as:” to PowerShell, as I do (also shown above).

As soon as you place this wordfile in that folder, you should see PowerShell as an option under View>View as (Highlighting File Type)

view as highlighting

Auto-complete

I’ve also created an auto complete file that contains the same cmdlet/function names as the syntax highlighting file. When enabled, you get tab completion of cmdlet and function names similar to the PowerShell console and ISE. Note, however, that in UltraEdit, you only get auto-complete of the cmdlet/function names, not their parameters.

You can save the file anywhere. Then, go to Advanced>Configuration>Editor>Word Wrap/Tab Settings to specify the location within UltraEdit:

auto-complete path

Then go to Auto-complete and check the box “Show auto-complete dialog automatically” and also enter a number in the box. 5 works for me.

auto-complete options

Now, when typing a cmdlet/function that’s in the auto-complete file, you’ll get suggestions.

auto-complete suggestions

Up/down errors navigate through the list, and tab uses the highlighted suggestion.

Download

UltraEditSyntaxHighlighingAuto-CompleteFiles.zip

Function: Set-PowerPlan – Adjust The Power Plan of a Server

February 25, 2014 Leave a comment

Just something I worked up based on a suggestion by someone. This will change the power plan of the machine it’s run on. This can be critical if you want to ensure that the machine doesn’t go to sleep while an extended process is running. Simply run the function with the desired power plan and the change is immediate. For example:

Set-PowerPlan "High Performance"

The three power plans you can choose from are “high performance”, “balanced”, and Power Saver. That’s all there is to it.

function Set-PowerPlan {
	[CmdletBinding(SupportsShouldProcess = $True)]
	param (
		[ValidateSet("High performance", "Balanced", "Power saver")]
		[ValidateNotNullOrEmpty()]
		[string] $PreferredPlan = "High Performance"
	)
	 
	Write-Verbose "Setting power plan to `"$PreferredPlan`""
	$guid = (Get-WmiObject -Class Win32_PowerPlan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").InstanceID.ToString()
	$regex = [regex]"{(.*?)}$"
	$plan = $regex.Match($guid).groups[1].value 
	
	powercfg -S $plan
	$Output = "Power plan set to "
	$Output += "`"" + ((Get-WmiObject -Class Win32_PowerPlan -Namespace root\cimv2\power -Filter "IsActive='$True'").ElementName) + "`""
	Write-Verbose $Output
}
Categories: PowerShell Tags: ,

Resetting the Font in Lync Server Control Panel – Goodbye Times New Roman!

January 20, 2014 4 comments

Many people have noticed that after installing the Lync Server 2013 Cumulative Update from October, 2013, that the font in the Lync Server Control Panel changed to Times New Roman from the original Segoe UI font.

LSCP font2

Lots of people commented online that they were not fans of the change (myself included), and wanted it changed back. The issue was raised with Microsoft who verified that there was no change in the font requested when displaying the Control Panel. This was confirmed by looking through the logs. The problem was an Internet Explorer compatibility issue. Servers that have IE 8 don’t exhibit the problem, but those with IE 9 or later, do. Instead of looking at the font defined by MS Shell Dlg registry value (HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitues\MS Shell Dlg), the Control Panel was using the font configured in IE. If you look in Internet Options>Fonts, you see that the Webpage font is set to Times New Roman.

LSCP font

We can get the original Segoe UI font back by simply changing the webpage font option to Segoe UI, closing the Control Panel, and opening it back up. We can also make the change using PowerShell by changing the value of the registry key that gets set when you use the above method. To do so, open PowerShell, and enter the following:

Set-ItemProperty -path "HKCU:\Software\Microsoft\Internet Explorer\International\Scripts\3" -Name IEPropFontName -Value "Segoe UI"

And after restarting the Control Panel, we see it’s back to the way it should be.
LSCP font3

You can set the value to any font, really, including Comic Sans MS, as requested by my buddy Ken “The Hoff” Lasko.

Something to keep in mind is that changing that value does have the potential for changing the way other web pages look as well, as this is more of a work-around than a fix. But I’ve not run into that, yet. I’ll post more info as I get it.

Review: Microsoft Exchange Server 2013 PowerShell Cookbook

August 8, 2013 Leave a comment

Microsoft Exchange Server 2013 PowerShell CookbookI like Exchange. And PowerShell. So, when Packt Publishing asked if I was interested in reviewing their latest book “Microsoft Exchange Server 2013 PowerShell Cookbook”, I jumped at the chance. I was even more excited when I realized that it was written by two heavy hitters, Jonas Andersson and Exchange MCM and Microsoftie Mike Pfeiffer. I’ve known Mike since his days as an Exchange MVP prior to joining Microsoft.

I had not read any books published by Packt previously, so I was interested to see how this one was put together. What a pleasant surprise. The book, now in its 2nd edition, wastes no time in dispensing some solid PowerShell knowledge with the first chapter, “PowerShell Key Concepts”. If you’re a complete newbie who has been reluctant to take the PowerShell plunge, this chapter has a substantial amount of information to help you get started. In fact, If you read the first chapter, you’ll have an excellent understanding of the basics of PowerShell. Not only is that a great building block for what comes later in the book, but it’s also a great PowerShell primer just by itself. If you’re an experienced coder, the first chapter will help fill in some gaps.

From there we go to common tasks in both PowerShell and Exchange. Some great info there, as well, as we look at many of the things that help tie scripts together including remote sessions, tasks, dealing with .csv files, etc.

From that point on, each subsequent chapter deals with a different area of Exchange, and how PowerShell can make life easier. These ars including topics such as mailbox and database management, high availability, and more. Each area is broken down into a specific subject, and includes information broken into several different sections, including “How to do it..”, “How it works..”, “There’s more..”, etc. These start with a simple task, explain the basics, and build on them so that the reader can develop great PowerShell functions and scripts, and understand what’s happening “under the hood”. In reading this book, I can say I’ve learned several different approaches to things that I had not considered previously.

Some things often get left out of Exchange books just due to the complexity of the product. This is often things like compliance. But, oh no – Mike and Jonas dive into this as well, discussing archiving, retention and legal holds, auditing, and more. There’s also a chapter on using the EWS Managed API, which really opens the door to doing all kinds of things by connecting to Exchange via EWS. Just look at what Glenn Scales is doing with EWS.

Chapters break down as follows:
Chapter 1: PowerShell Key Concepts
Chapter 2: Exchange Management Shell Common Tasks
Chapter 3: Managing Recipients
Chapter 4: Managing Mailboxes
Chapter 5: Distribution Groups and Address Lists
Chapter 6: Mailbox Database Management
Chapter 7: Managing Client Access
Chapter 8: Managing Transport Service
Chapter 9: High Availability
Chapter 10: Exchange Security
Chapter 11: Compliance and Audit Logging
Chapter 12: Server Monitoring and Troubleshooting
Chapter 13: Scripting with the Exchange Web Services Managed API

The book also contains some great reference materials in the appendices. A common shell appendix is a great add-on to what’s in the book, especially chapter 1. I probably learned more from this part of the book than anything.

Appendix B delves into query syntaxes – something that can be frustrating if you don’t know the basics and pitfalls. From AND and NOT to date ranges and more. Solid info that should be kept within arms reach.

I have to say, it’s no surprise that I liked this book. Mike and Jonas did a fantastic job keeping the reader engaged. By taking a simple idea and building on it, each example and section helps solidify a solid PowerShell understanding and how it relates to Exchange. Installation, configuration, and administrative tasks are all made substantially easier by the information in this book. The book doesn’t talk over the reader’s head, and the code provided is solid and clean. I can’t recommend this book enough if you’re an Exchange person looking to get into PowerShell to increase your productivity and enhance your career.

The book is available from Packt Publishing in formats including print, ebook, and .pdf, and from Amazon as a printed book, or Kindle download. Buy it! Now!

One liners: Get the Top 5 Errors From An Event Log

Powershell_logo-137x137As part of an Active Directory Health Check (think “ADRAP”), I needed to document the top errors and warnings in several event logs, including the System, Application, DNS, Directory Service, FRS, and others. This list also needed to include the source of the errors. Since there were a bunch of domain controllers, I didn’t want to spend all day manually looking through event logs, filtering, etc. PowerShell to the rescue.

Get-EventLog is pretty self explanatory. We tell this command we want to look at the system event log, and we’re only interested in errors. We could look for other event types, too, such as Information, FailureAudit, SuccessAudit, and Warning. Get-EventLog can filter based on dates, usernames, etc.

We then take the output of that, and pipe it to Group-Object (or “Group” for short). We group based on source and eventID. This lumps all of the same events with the same eventID together as one object. This is important, because if there are errors with the same source, but different eventID, we want those listed separately.

Next, we use Sort-Object, or “sort”, to arrange the results into a usable list, with the highest numbers at the top. Since we only need the top 5 in the list for this exercise, Select-Object, or “select”, comes into play. This will return just the number of objects we specify. In this case, that’s 5. Since we pass the -first parameter to this cmdlet, we get the first 5 results that were piped from the previous command. Essentially, the highest 5 objects. And lastly, we display just the count and the name using Format-Table, or “ft”. Since we grouped the source and eventID together, the name will be the name of the source, and the corresponding eventID. The output looks like this:

Count Name
----- ----
  179 Microsoft-Windows-GroupPolicy, 1006
   30 Service Control Manager, 7031
   19 Microsoft-Windows-Hyper-V-Netvsc, 2
   15 Service Control Manager, 7034
   10 Microsoft-Windows-WindowsUpdateClient, 20

Exactly what I was after. The top 5 errors in the system event log, sorted by how many times the error appeared in the log, with the source name and eventID, sorted. The one-liner looks like this:

Get-EventLog -LogName system -EntryType error | Group source,eventid | Sort count -desc | Select -first 5 | Ft count,name

We could also strip off the ft stuff, and use Export-Csv to dump the results to a csv file.

Get-EventLog -LogName system -EntryType error | Group source,eventid | Sort count -desc | Select -first 5 | Export-Csv c:\SystemErrors.csv -Not

Pretty straightforward, and fairly quick, as long as your event logs aren’t huge. We can even target remote computers by appending the -ComputerName parameter to the Get-EventLog cmdlet. For example:

Get-EventLog -LogName system -EntryType error -ComputerName mycomputer.contoso.local | Group source,eventid | Sort count -desc | Select -first 5 | Export-Csv c:\SystemErrors.csv -Not

 

Categories: PowerShell Tags: ,

Function: Get-PstFiles – List All .pst Files In A Given Path, With Name, Path, Size, and Owner

May 13, 2013 4 comments

Exchange 2013 logo 128x128Description

If you need to make a list of the .pst files in a given path, this function should help. It will get all .pst files, their name, path, size (in MB), and owner. This should help if you’re looking at importing the files in Exchange Server. If you’d like to export the results to a file, use the -file switch, with a filename, and the function will save the info to a .csv file.

Syntax

Get-PstFiles [[-path] ] [[-filter] ] [[-file] ] [-WhatIf] [-Confirm] []

Download

v1.1 – 05-13-2013 Get-PstFiles.v1.1.zip

Syntax Highlighting File for UltraEdit Includes Exchange 2010/2013, Lync 2010/2013, and ActiveDirectory cmdlets

May 8, 2013 3 comments

In a previous post, Exchange 2010 and Lync 2010 PowerShell syntax highlighting file for UltraEdit, I included the cmdlets for both Exchange 2010 and Lync 2010. In this new file, I’ve included Lync 2010, Lync 2013, Exchange 2010, Exchange 2013, and Active Directory cmdlets for highlighting. If you use UltraEdit, this wordfile may make life a little easier.

Download the file here: UltraEditPowerShellLyncExchangeAD.zip