Friday, August 23, 2013

Change authentication account in NTLM Webapplication

#Usage:.Change-NTLMAccount -rms "rms.contoso.com" -currentaccount 'curracct' -newAccount 'newacct'

param([string] $rms,$currentAccount,$newAccount)

function DisplayUpdate ($str, $color = "white") {
$now = [DateTime]::Now

Write-Host "[$now]" -ForegroundColor white -NoNewline
Write-Host " $str`r" -ForegroundColor $color
}

$scriptPath = split-path -parent $MyInvocation.MyCommand.Path
$managementGroupRmsName = $rms
$newActionAccountName = $newAccount
#Load Dll's
Displayupdate "Loading SDK dll's"
$void1 = [System.Reflection.Assembly]::LoadFrom("$scriptPathMicrosoft.EnterpriseManagement.Core.dll")
if(!$void1) {Displayupdate "DLL's not found..exiting..." "red";break;}
$void2 = [System.Reflection.Assembly]::LoadFrom("$scriptPathMicrosoft.EnterpriseManagement.OperationsManager.dll")
if(!$void2) {Displayupdate "DLL's not found..exiting..." "red";break;}
$void3 = [System.Reflection.Assembly]::LoadFrom("$scriptPathMicrosoft.EnterpriseManagement.Runtime.dll")
if(!$void3) {Displayupdate "DLL's not found..exiting..." "red";break;}
$mg = New-Object Microsoft.EnterpriseManagement.ManagementGroup($managementGroupRmsName)
Displayupdate "connected to MG:$Mg.name"
Displayupdate "Getting mps.."
$mps = $mg.getmanagementpacks() | where{$_.name -match "NTLM"}
if($mps.count -gt 0 ) {
$count = $mps.count
Displayupdate "[$count] number of mp's found" "yellow"
$healthServices = dir -R | where {$_.UniquePathName -like "Microsoft.SystemCenter.HealthService*"}
$Srs = $mg.getmonitoringSecurereferences() | where{$_.name -match "WebApplication"}
$healthServices = dir -R | where {$_.UniquePathName -like "Microsoft.SystemCenter.HealthService*"}
$newActionAccount = $mg.GetMonitoringSecureData() | where {$_.UserName -eq $newActionAccountName -and $_.Type -eq "Windows" -and $_.name -notmatch "Data Warehouse Report Deployment Account"}

foreach($sr in $Srs)
{
$secureDataHSRefs = $mg.GetMonitoringSecureDataHealthServiceReferenceBySecureReferenceId($sr.Id)
foreach($secureDataHSRef in $secureDataHSRefs){
$healthService = $mg.GetMonitoringObject($secureDataHSRef.HealthServiceId)
$currentActionAccount = $mg.GetMonitoringSecureData($secureDataHSRef.MonitoringSecureDataId)
DisplayUpdate "Changing Action Account on $($sr.GetManagementpack().Displayname)" "yellow"
$secureDataHSRef.MonitoringSecureDataId = $newActionAccount.Id
$secureDataHSRef.Update()
}
}
}

else
{
Displayupdate "No NTLM mp's found..exiting.." "red"
break;
}

DisplayUpdate "Script finished"

No comments:

Post a Comment