PowerShell

Force SCCM Distribution Point to refresh failed packages

If a Distribution Point in System Center Configuration Manager has failed packages it probably has a cause and resending the packages might not be the right solution to the problem. But I had the need to resend all failed packages on a distribution point and I was in no mood to click around in the GUI so I investigated the WMI classes listed on MSDN: http://msdn.microsoft.com/en-us/library/hh949540.aspx First of all, what I am looking for is packages on a certain distribution point.

Where() method in powershell 4 breaks my objects!

Boe Prox wrote an excellent post on the new Where() and Foreach() methods in Powershell Version 4 over at his blog: http://learn-powershell.net/2013/11/26/checking-out-the-where-and-foreach-operators-in-powershell-v4/ I decided to play around with these a bit and discovered a behavior I didn’t expect. When using the Where() method instead of Where-Object, the output differ and I can no longer access and update my original object. This is because Where() always returns a collection of objects (even if it’s only a collection of one object).

PowerShell Tip: Gracefully close a process

Killing a process is easily done by using the cmdlet Stop-Process, but it has a tendency to stop those processes somewhat ungracefully. Lets take an example of using notepad.exe This script will start a new instance of notepad.exe, enters some important data and waits for three seconds: add-type -AssemblyName microsoft.VisualBasic add-type -AssemblyName System.Windows.Forms $Process = Start-Process notepad.exe -PassThru Start-Sleep -Milliseconds 500 [Microsoft.VisualBasic.Interaction]::AppActivate($Process.Id) [System.Windows.Forms.SendKeys]::SendWait("This is some some important data") Start-Sleep -Seconds 3 Now that we have a process with some unsaved data lets get to the point.

Subscriptions in SCOM 2007 automatically disabled

This post is all about an old and well known issue but I haven’t found any automated solution to it so I’d like to share mine. But first an introduction: When editing a subscription in System Center Operations Manager 2007 the subscription is tagged with the SID of the administrators user account. This is all good until the day that that account is removed from the SCOM administrators role. And maybe, if the administrator in question leaves the company, the account is even removed from Active Directory.

Use Powershell to merge XML

Let’s say that we have to XML documents each containing a list of books (I’m using the XML example file from this page since I’m too lazy to write my own) and we want to join them to one XML. File1.xml looks like this: <?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.