Skip to content


New Job – Change of focus.

Wow it has been a long time since I have posted here. So here is what has changed.

I got laid off from the place that used SCOM and Power Shell, and now work for a company that uses *nix servers. Unfortunately, this has brought about a “use it or lose it” scenario. My PowerShell skills have diminished.

This will be changing though. I have a few projects I am working on for HackTheMind, LLC. that will require PowerShell, and as I get them completed, I will post writeups on them.

Take care, and keep scripting.

Posted in Uncategorized.


Privacy rights attacked at City Level.

I know I know. This is not SCOM or Posh related, but I feel it is of too note.

I will not go into the long boring details, instead, I will just paste the email I sent which has more then enough information.

——————————————————————————————

From: Jason M. Rydstrand
Sent: Thursday, June 18, 2009 3:42 PM
To: gsullivan@bozeman.net
Cc: aclu@aclumontana.org; BJ@KISW.com; newstips@king5.com; bethg@privacyrights.org
Subject: Breach of Privacy Rights and Terms Of Service
Hello Greg,
 
I am writing you in response to the news article I stumbled across.
 
 
After doing some research at the City website, I confirmed that the background check asks for Website Addresses as well as User Names and Passwords that the applicant utalizes.
 

http://www.bozeman.net/bozeman/humanResource/forms.aspx

 

The part that has the form in question:

 

Consent and Release to Conduct a Criminal Background Check (Notarized Version)

 
The problem with asking for this information is three fold.
 
1. The laws state that a employer can not ask for age, race, creed, and many other points of information of a applicant.
 
The problem is, a facebook profile commonly contains this information, and by asking for the said profile, one is also asking for the protected information.
 
2. Please list any and all, past and present, personal or business website or web pages, memberships on any Internet-based chat rooms, social clubs or forums, to include but not limited to: Facebook, Google, Yahoo, YouTube.com, MySpace, etc
 
Now, if one was to take this literally, you are also asking for Internet Banking information. That would set a applicant up for identify theft, and in turn the City would be liable. This also includes email accounts, as YouTube and GMail utalize the same passwords, and private communications protected.
 
3. Terms Of Service (TOS)
 
Many providers of these sites specificly state that one can not share their login credentials with other parties. This means, that by requiring this information in a background check, you have opened the applicant to a lawsuit from the Service Provider.
 
You will notice that I have CC’d the ACLU and a couple media outlets in regards to this.
 
Thank you for your time,
Jason Rydstrand

Posted in Uncategorized.


Monkey Wrench – SCOM R2

Well, sure enough they released R2 on the 23rd like they said they would. What they didn’t say was it was the EVAL only.

Only under a couple days ago did I get confirmation that even people in the Software Asurance Program wouldn’t get R2 proper until the 1st of July. Bleh.

Posted in RC2, System Center Operations Manager.


System Center Operations Manager 2007 R2 – RTM!

As alot of others are saying, the R2 RTm EVAL has been relased to the public.

You can download it here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=93ddf25b-1ef0-4851-81b0-5fb9a2f76181&displaylang=en

YAY!

Posted in RC2, System Center Operations Manager.


Change IIS 6.0 Home Directory

The following script can be used to change all the websites on a server or group of servers to the same webroot.
#==============================================================================================
#
# Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009
#
# NAME: Set-Webroot.ps1
#
# AUTHOR: Jason Rydstrand
# DATE  : 5/15/2009
# VERSION: 1.1
#
# COMMENT: This script is for changing the Webroot on systems.
#
# REQUIREMENTS: 1. Powershell V2
#    2. RPC Access from system script is running on.
#
# CHANGED: 1. Created functions for each step.
#     2. Added comments.
#     3. Added Powershell version checking.
#     4. Added UserValidation before Changes are made.
#     5. Added capability for more then one sytsem to change at a time.
#
# TODO: 1. Pull system from VIP (Not implimented in this version.)
#  2. Wait for system connections to drop. (Not implimented in this version.)
#  4. Do a HTTP Get to spin up IIS. (Not implimented in this version.)
#  5. Put back in VIP. (Not implimented in this version.)
#
#==============================================================================================

# Functions
#==============================================================================================

# Function to validate version of Powershell is V2

function CheckVersion
{
 Write-Host "Checking for Powershell V2"
 
 if($host.version.Major -ne "2")
 {
  Write-Host "This script requires Powershell Version 2."
  Write-Host "Please download and install Powershell V2 from"
  Write-Host "<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c913aeab-d7b4-4bb1-a958-ee6d7fe307bc&displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=c913aeab-d7b4-4bb1-a958-ee6d7fe307bc&displaylang=en</a>"
  break
 }
 else
 {
  Write-Host "Powershell V2 Detected."
  Write-Host " "
 }
}

# Function to build array of machines for processing.

function InputMachines
{
 Write-Host "Please input machines. Example: system1 system2 system3 "
 $machines = (Read-Host "Machines").Split(" ")
 Write-Host " "
 return $machines
}

# Function to get new Home Directory

function GetDirectory
{
 Write-Host "Please input new IIS Home Directory. Example: E:\webroot_a"
 $webroot = Read-Host "Directory"
 Write-Host " "
 return $webroot
}

function UserValidation
{
 Write-Host "The following systems will be changed:"
 Write-Host " "
 foreach($machine in $machines)
 {
  Write-Host "$machine - $webroot"
 }
 Write-Host " "
 Write-Host "Are these correct?"
 $yesno = Read-Host "Yes/No?"
 if($yesno -eq "Yes")
 {
  Write-Host "Continueing."
 }
 else
 {
  Write-Host "&lt;&lt;&lt; User did not indicate these are correct &gt;&gt;&gt;"
  break
 }
}

function ChangeVirDir
{
 foreach($machine in $machines)
 {
  $iis = Get-WmiObject -class iiswebvirtualdirsetting -namespace "root\microsoftiisv2" -computer $machine -authentication 6 -Credential $credentials
 
  # Count number of websites.
  $i = $iis.count

  # Set array start
  $j = 0

  # Loop through each website.
  while($i -gt 0)
  {
   # Set path for local object of website
   $iis[$j].Path = "$($webroot)"

   # Put local object on remote host
   $iis[$j].Put()
 
   # Increment Counters
   $j++
   $i--
  }
 }
}
#==============================================================================================
# End Functions

# Main Script Body Start
#==============================================================================================

# Check Powershell Version

CheckVersion

# Notify User what script is for.
Write-Host "This script is to switch a machine, or group of machines, IIS Home Directory."
Write-Host "The following will be done by this script:"
Write-Host "1. Pull system from VIP (Not implimented in this version.)"
Write-Host "2. Wait for system connections to drop. (Not implimented in this version.)"
Write-Host "3. Change IIS Home Directory."
Write-Host "4. Do a HTTP Get to spin up IIS. (Not implimented in this version.)"
Write-Host "5. Put back in VIP. (Not implimented in this version.)"
Write-Host " "
Write-Host "Asking for user credentials."
$credentials = Get-Credential
Write-Host " "
# Set what machine to hit
$machines = InputMachines

# Set path you want Home Directory to be.
$webroot = GetDirectory

# Inform user of what systems will be changed to what directory.

UserValidation

# Make change

ChangeVirDir

#==============================================================================================
# End of Main Script Body

Posted in Powershell, V2.


MMS 2009 – The first day.

Well, this year, so far, all I can say is they are better organized. They put the registration in a actual room this time, so they could control the madness that happened last year. In other words, it only took me 10 minutes to register this time, instead of 2.5 hours.

Notes will be comming soon.

Posted in RC2, System Center Operations Manager.


Version Check from Powershell

While on the phone with Microsoft I needed a way to check the version of the mommodules.dll on alot of systems to see if the patch was applying.

So, I tweaked a script I found long ago and then made it work in Powershell V1 (with help from #powershell user JasonMArcher). I would give credit to the original author, but I don’t remember who it was. (aka, if you are reading this, please let me know so I can give proper credit.)

$erroractionpreference = "Continue"

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "File Name"
$c.Cells.Item(1,3) = "Version"
$c.Cells.Item(1,4) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-content E:\SCOMScripts\patching\Servers.txt

foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow,1) = $strComputer

Function GetFileInfo
{

$Path = "\\"+ $strComputer + "\C$\Program Files\System Center Operations Manager 2007\MOMModules.dll"

$File = get-item $Path

$c.Cells.Item($intRow,2) = $File.Name
$c.Cells.Item($intRow,3) = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($Path).ProductVersion
}

GetFileInfo

$c.Cells.Item($intRow,4) = Get-date
$intRow = $intRow + 1
}

$d.EntireColumn.AutoFit()


 

I did some modifications and here is another version that get’s the machine names from SCOM. This has to be ran from the Operations Manager Console.

$erroractionpreference = "Continue"

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "File Name"
$c.Cells.Item(1,3) = "Version"
$c.Cells.Item(1,4) = "Report Time Stamp"
$c.Cells.Item(1,5) = "Reporting Node"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-agent

foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow,1) = $strComputer.ComputerName

Function GetFileInfo
{

$Path = "\\"+ $strComputer.ComputerName.ToString() + "\C$\Program Files\System Center Operations Manager 2007\MOMModules.dll"

$File = $Path

$c.Cells.Item($intRow,2) = $File
$c.Cells.Item($intRow,3) = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($Path).ProductVersion
}

GetFileInfo

$c.Cells.Item($intRow,4) = Get-date
$c.Cells.Item($intRow,5) =  $strComputer.PrimaryManagementServerName
$intRow = $intRow + 1
}

$d.EntireColumn.AutoFit()

Posted in Powershell, V1.


Lost rule looking for a good home.

Have you every created a rule, and then a month later realize you need to change something on it? Sure.

Only you can’t seem to find it because your SCOM UI locks up and crashes when you try to have full scope to find it? Ohh yeah.

Then this one line is for you.


((get-rule | ? {$_.DisplayName -like "*RuleName*"}).getmanagementpack()).displayname

That’s all it takes. Just change where is says *Rule Name* to match the name, or part of the name your rule has, and hit enter. It will output the MP it’s in.

Have fun.

Posted in Powershell, RC1, System Center Operations Manager, V1.


Basic XML Server Lists and Powershell

While at work, one of my coworkers was attempting to read a XML file with powershell, and couldn’t get it to work.

After looking at it a moment, it dawned on me of a way to have server lists that one can use for automation.

Let us say you have a XML file like the following:

<?xml version=”1.0″ encoding=”utf-16″ ?>
<Objs Version=”1.1.0.1″ xmlns=”http://schemas.microsoft.com/powershell/2004/04″>
   <DataCenter1>
       <FrontEnd>
           <Servers>webserver1</Servers>
           <Servers>webserver2</Servers>
          <Servers>webserver3</Servers>
      </FrontEnd>
      <BackEnd>
          <Servers>datalayer1</Servers>
          <Servers>datalayer2</Servers>
      </BackEnd>
   </DataCenter1>
</Objs>

This is a very simple XML file, that one might use to tell the difference between the front end systems and the back end systems in a datacenter.

Now, how would you load this into powershell?
PS C:\Powershell> [xml]$Servers = gc .\servers.xml
Once that is done, you can now grab things from the XML loaded into $Servers.
PS C:\Powershell> $Servers.Objs.DataCenter1.FrontEnd.Servers
webserver1
webserver2
webserver3

As you can see, this gave me the list of servers under the FrontEnd element.

So to use this, in a foreach loop for example, just do the following foreach.
foreach($Server in $Servers.Objs.DataCenter1.FrontEnd.Servers)
{
Write-Host "$Server is a Front End Server."
}
foreach($Server in $Servers.Objs.DataCenter1.BackEnd.Servers)
{
Write-Host "$Server is a Back End Server."
}

This will give you the following.
webserver1 is a Front End Server.
webserver2 is a Front End Server.
webserver3 is a Front End Server.
datalayer1 is a Back End Server.
datalayer2 is a Back End Server.

Very basic XML usage, but it was enough to give my co-worker a running start.

Later

Posted in Powershell, V1, V2.


Verifying a management pack using the SCOM SDK

So I came across quite a problem when I lost one of the MP files for one of my custom management packs.  I had a new, updated version, but how do I verify upgrade compatibility without the file?

In a normal situation when you have both of the files, you can use the mpverify.exe utility to do so.  That would look something like this:

mpverify managementpack.xml /I C:\MyManagementPackDir /CheckUpgrade C:\OldMPs\OlderVersionOfMP.xml

I was in quite a quandry because I lost the older version. However, there is an option!

Using the Microsoft.EnterpriseManagement.Configuration namespace, there is a handy class called ManagementPack, which in turn has a member called CheckVersionCompatibility()

At first, I was a little puzzled, as this method can only check the instance of ManagementPack against an OLDER version of itself.

Soon after I realized the constructor for ManagementPack can take a file path. Looks something like this:

$newmp = [Microsoft.EnterpriseManagement.Configuration.ManagementPack](“C:\InsertMPNameHere.xml”)

So now I have my updated version in an Object, from which I can call the CheckVersionCompatibility() method, which will verify the managementpack for me, which looks like:

$currentmp = get-managementpack –name “InsertMPNameHere”
$newmp.CheckVersionCompatibility($currentmp)

Sweet! It works! But wait. It tell me it worked, how can I be sure? It returns System.Void?

After consulting with the infamous Jakub@Work, he ensured me that the only time it fails is when it throws a ManagementPackException.

They could have at least told it to return 0 if it worked correctly. Instead the only option is to hope it throws an exception to tell you something is wrong.

So, if you’re going to use ManagementPack.CheckVersionCompatibility(), put it in a trusty try-catch statement so you can handle the exceptions in the way of your choice.

Posted in Powershell, RC1, System Center Operations Manager, V1.