Monthly Archives: March 2011

Calling a function in PowerShell

This is a quick example that shows how you can call a function in PowerShell.  The example has a function that accepts an Active Directory (AD) Organisation Unit (OU) name, enumerates the computers within that OU and kills any process with the name “Application1.exe”.

Create two files in a folder called PowerShell in the root of C:\, one called KillProcess.ps1, which will contain the function and another called EnumPCsKillProcess.ps1, which will call the function.  Below is the contents of each file:

KillProcess.ps1

Function KillProcess
{
ForEach ($child In $ou.psbase.Children)
{
if ($child.ObjectCategory -Like ‘*computer*’)
{
$Procs = gwmi -ComputerName $child.Name -Query “Select * from Win32_Process Where Name = ‘Application1.exe'”
ForEach ($Proc In $Procs)
{
Write-Host $child.Name
$Proc.Terminate()
}
}
}
}

EnumPCsKillProcess.ps1

. C:\PowerShell\KillProcess.ps1
$ou = [ADSI]”LDAP://OU=ENTER 1ST OU PATH HERE”
KillProcess
$ou = [ADSI]”LDAP://OU=ENTER 2nd OU PATH HERE”
KillProcess

The key line is the one in red above, which references the KillProcess.ps1 file, which contains the function.

Advertisements

Unable to “Turn off redirected access for this Cluster shared volume”

Our five node Hyper-V cluster is connected to a Dell MD3000i, which provides virtual machine storage using Cluster Shared Volumes (CSV).  The MD3000i has dual storage controllers for redundancy, but recently both storage controllers rebooted within a minute of each other.  Looking at the Storage section of Failover Cluster Manager showed that half the CSV volumes had a status of Redirected Access.  Reading this blog http://blogs.technet.com/b/askcore/archive/2010/12/16/troubleshooting-redirected-access-on-a-cluster-shared-volume-csv.aspx showed that the first thing to try was to “Turn off redirected access for this Cluster shared volume”, unfortunately this didn’t work.  I looked in Disk Management on each of the five nodes, which looked as below:

Each node should be able to see all the disks, but only the first node, the one on the far left, could see all five disks.  I live migrated the virtual machines off each node and rebooted each node one at a time.  Once completed, Disk Management looked like this:

 

Every node can see all five disks.  I checked Failover Cluster Manager and all the CSV volumes had returned to Online status automatically.