The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

SimonM (4) [Avatar] Offline
#1
I found a good article on using Powershell with MOM 2005, which gives the basics for loading the necessary dll's and accessing the MOM Administrator class.

Im trying to take the basics from this article here:
http://mow001.blogspot.com/2006/06/powershell-and-mom-2005.html

And expand it. In particular, I want to access selected computers and set them to agent-un managed.

Has anyone experimented with this?

I have a script to add or remove a computer from a group, but thats as far as I have managed to get.

# get group members (having already found GUID)
$group = $mom.GetComputerGroup('12345678-1234-1234-1234567890ab')
$group.ComputerIncludeList
""
#
"# Add new member ...."
$group.AddComputerToIncludeList('servername')
$group.ComputerIncludeList

# apply the update
$group.update()
""

Im not certain if the necesary classes are available in the MOM 2005 sdk? Does anyone know more?

Thanks,

Simon.
SimonM (4) [Avatar] Offline
#2
Re: PowerShell & MOM 2005
I have got much further with this now. To switch a specified computer from managed to un-managed:

# specify computer group
$guid='12345678-1234-1234-1234567890ab'
$srvname="SERVERNAME"
$group = $mom.GetComputerGroup($guid)
$members=$group.getAssociatedComputers()

$server=$members | where-object {$_.name -eq $srvname}

#output server properties
"Server : $($server.name)"
"Domain : $($server.domain)"
"Management Type: $($server.managedtype)"
""

# switch managedtype
if ($server.managedtype -eq "unmanaged"){"Setting server from Unmanaged to Agent managed...."
# $chg=$server.changeManagedType(2,$dusr,$dpwd)
$chg=$server.changeManagedType(2)
$server.refresh()
}
if ($server.managedtype -eq "agent"){"Setting server from Agent managed to unmanaged...."
# $chg=$server.changeManagedType(0,$dusr,$dpwd)
$chg=$server.changeManagedType(0)
$server.refresh()
}


Or to place a group of computers into Maintenance Mode:

[string]$reason="Testing maint mode"
$durationHours=1
$endtime=(get-date).addhours($durationhours)

#get group members
$group = $mom.GetComputerGroup('12345678-1234-1234-1234567890ab')
$members=$group.getAssociatedComputers()

$cm = $mom.GetComputerMaintenanceObject()

foreach ($computer in $members) {
if ($computer.IsInMaintenanceMode){"$($computer.name) is already in maintenance mode"}
else {
$cm.SetMaintenanceMode($computer, $endtime, $reason)
"$($computer.name) is now in maintenance mode until $endtime"}
}

Maybe these are useful for others?

My final problem is to do with pageing of results. To keep things manageable, its best to use a small group of computers. But if the group contains more than 100 members, this is split into pages.

How would I access the second page of results? e.g.

$group = $mom.GetComputerGroup('12345678-1234-1234-1234567890ab')
$members=$group.getAssociatedComputers()
foreach ($m in $members){"$($m.name)"}

This will only output 100 computers and then stop. Any idea how to see the rest?

Thanks!
Tyler Durden (1) [Avatar] Offline
#3
Re: PowerShell & MOM 2005
> My final problem is to do with pageing of results. To
> keep things manageable, its best to use a small group
> of computers. But if the group contains more than 100
> members, this is split into pages.
>
> How would I access the second page of results? e.g.
>
> $group =
> $mom.GetComputerGroup('12345678-1234-1234-1234567890ab
> ')
> $members=$group.getAssociatedComputers()
> foreach ($m in $members){"$($m.name)"}
>
> This will only output 100 computers and then stop.
> Any idea how to see the rest?
>
> Thanks!

This should do it:

$members = $group.getAssociatedComputers()

// loop through the paged collection
do {
foreach($member in $members) {
Write-Host "$($member.Name) - $($member.Domain)"
}
$members.Next(); // Get next page...
} while($members.CurrentCount > 0);

Look also for http://msdn.microsoft.com/en-us/library/ms814937.aspx