• Quick PowerShell script to run a command on every machine in an OU

    I wanted to run a command on all machines in an OU. I know this documented all over the place, but this is the syntax I like:

    foreach ($COMPUTER in $(Get-ADComputer -Filter * -Searchbase 'OU=SubOU,OU=TopLevelOU,DC=DOMAIN,DC=LOCAL')){
      write-host "Connecting to $($COMPUTER.Name)"
      Invoke-Command $COMPUTER.Name {ipconfig /renew}
    }
    

  • Install OpenManage Server Administrator on ESXi5 via PowerCLI

    Dell has changed how you install OpenManage Server Administrator on ESXi5. To do this via PowerCLI, use the following steps.

    1. Download the new vib file: OM-SrvAdmin-Dell-Web-6.5.0-542907.VIB-ESX50i_A02.zip (most recent can be found here)
    2. Extract it and upload the folder via the vSphere client (browse datastore and upload the extracted folder)
    3. Put the ESXi5 box into maintenance mode.
    4. From PowerShell with the PowerCLI installed:
      1. Connect- VIServer -Server x.x.x.x
      2. Install-VMHostPatch -HostPath /vmfs/volumes/datastore1/OM-SrvAdmin-Dell-Web-6.5.0-542907.VIB-ESX50i_A02/metadata.zip (or where ever you uploaded it)

    Note: You can no longer connect directly to that web interface on port 1311 of the ESXi5 box. Now, you now have to go to a different OpenManage Server Administrator install (log out if you are auto logged in) and select “Manage remote node”. That is a pain.


  • jbmurphy.com’s first year in blogging


    I had a goal last year, a goal of blogging 2 times a week for the entire year. I ended up with 116 posts. A couple of those posts were a few dates late, so I did not meet my exact goal of 2 times week, but I always managed 4 posts in every two weeks. My year end results are 16,368 visits and 14,067 unique visitors. Fun stuff.  I know is it no much, but I see a upward trent in the graph below! Wonder where I will be next year?

    I hope my tech ramblings are useful to the 14,067 people that visited my site.


  • SQL query to find the number of WordPress posts this year!

    I was compiling my year end wrap up (hits, posts, twitter followers), and I realized I did not know how many posts I created this year. I ran the following query again my WordPress database to find out.

    select post_date,post_title from wp_posts where post_type = ‘post’ AND post_status = ‘publish’ AND post_date like ‘%2011-%’;

    My goal was 2 a week for a year. I ended up with 116.

    More on this later.


  • PowerShell script to add Active Setup registry entries

    I am interested in using Active Setup more throughout our environment. The thing I like about Active Setup is that if I screw up, it will only run once and not over and over! Kidding, but the “run one” nature of Active Setup is nice. I wanted a PowerShell function to create Active Setup registry entries, so I can script the updates on multiple machine. Here is that function:

    Function JBMURPHY-AddToActiveSetup {
      Param([parameter(Mandatory = $true)]$ActiveSetupUniqueName,
    	[parameter(Mandatory = $true)]$ActiveSetupStubPath,
    	[parameter(Mandatory = $true)]$ActiveSetupVersion)
      $ParentKey="HKLM:Software\Microsoft\Active Setup\Installed Components"
      $Key=$ParentKey + "\" + $ActiveSetupUniqueName
      # Check for key
      if (!(Test-Path $Key)){
        New-Item -type Directory $($ParentKey + "\" + $ActiveSetupUniqueName)
      }
      else {
        write-host "Key exists"
      }
      Set-ItemProperty $($Key) -name "StubPath" -value $ActiveSetupStubPath
      Set-ItemProperty $($Key) -name "Version" -value $ActiveSetupVersion
    }
    

  • Updated PowerShell to determine if a user is visiting the office

    I made an error. More like an incorrect assumption in this post, specifically this code.:

    Function JBMURPHY-AD-GetHomeSite {
    Param($username=$(cat env:username))
    foreach ($group in "OfficeGroup1","OfficeGroup2","OfficeGroup3") {
        foreach ($user in $(Get-ADGroupMember $group)){
        if ($user.SamAccountName -eq $username) {return $group}
        }
    }
    }
    

    My incorrect assumption was that the AD PowerShell components were installed on every machine (they are only my machine). I needed to rewire this code above to use ADSI, since Get-ADGroupMember is not on everyone’s machine. Below is that code:

    Function JBMURPHY-AD-GetHomeSite {
    Param($username=$($env:USERNAME))
    $groups=([AdsiSearcher]"samaccountname=$username").Findone().properties.memberof | % {([adsi]"LDAP://$_").cn}
    foreach ($officegroup in "OfficeGroup2","OfficeGroup2","OfficeGroup3") {
        foreach ($group in $groups){
        if ($group -eq $officegroup) {return $group}
        }
    }
    }
    

  • PowerShell wrapper function to display a dialog box

    I wanted a function that I could pass some text, and it would put that text in a dialog box for the user to click okay. Simple, but I will reuse it I am sure.

     

    Function JBMURPHY-DisplayWindowsForm(){
    Param([parameter(Mandatory = $true)]$TextToDisplay,
    $Title="DefaultTitle")
    		[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    		[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    		$objForm = New-Object System.Windows.Forms.Form 
    		$objForm.Text = $Title
    		$objForm.Size = New-Object System.Drawing.Size(600,500) 
    		$objForm.StartPosition = "CenterScreen"
    		$OKButton = New-Object System.Windows.Forms.Button
    		$OKButton.Location = New-Object System.Drawing.Size(250,400)
    		$OKButton.Size = New-Object System.Drawing.Size(75,23)
    		$OKButton.Text = "OK"
    		$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
    		$objForm.Controls.Add($OKButton)
    		$objLabel = New-Object System.Windows.Forms.Label
    		$objLabel.Location = New-Object System.Drawing.Size(10,20) 
    		$objLabel.Size = New-Object System.Drawing.Size(500,400) 
    		$objLabel.Text = $TextToDisplay
    		$objForm.Controls.Add($objLabel) 
    		$objForm.Topmost = $True
    		$objForm.Add_Shown({$objForm.Activate()})
    		[void] $objForm.ShowDialog()
    }
    

  • After removing last Exchange 2003 Server, mail enabled public folders no longer work

    We decommissioned our last Exchange 2003 server the other day. All seamed well and I thought we were done.

    Nope.

    A few days later we had our scheduled downtime to apply patches, and I rebooted all three of our Exchange 2010 servers (for the record we are Exchange 2010 SP1 UR3 v3). Next morning people were getting bounce backs from messages destined to mail enabled public folders. The error  in the bounce back was:

    #554 5.2.0 STOREDRV.Deliver.Exception:ObjectNotFoundException; Failed to process message due to a permanent exception with message The Active Directory user wasn’t found. ObjectNotFoundException: The Active Directory user wasn’t found. ##

    I found this thread and this post. The error (as both posts suggested) boiled down to an empty server container from the decommissioned Exchange 2003 infrastructure. This blog post recommend against cleaning all the old entries, so we were nervous about making the change. Seemed unlikely that a single EMPTY container would be causing such a large issue.

    We contacted technical support (without mentioning our findings) and they said the exact same thing as our findings above – to remove the empty servers container. When I asked why this single container is causing the problem, they said “This happens because we assume that if a Servers container exists, there will be a System Attendant object somewhere inside it.” To me, this really does not explain “why”, but it was all they offered. We also asked if the deletion of the servers container would impact any other systems and they said “no”. Our final question was: once deleted, did we need to restart services/servers, and they said “no”.

    We backed up AD (system state and the C: drive of the PDC) and deleted the empty servers container, held our breath, and . . . all was good. Mail immediately started flowing to the mail enabled public folders.

    I thought I would write this up to supplement the above posts, and to add to our experience. Maybe this will help some one? Leave a comment if this helped!