Script changement datastore

Aujourd’hui un petit script pour changer la configuration du datastore sur tous les serveurs d’une ferme. Pratique quand on doit migrer le datastore! Le script redémarre le service IMA et les services dépendants.

 

$username ="MyUser"
$password="MyPwd"
$dsnfilename="Path/to/my/newdsn"

Get-xaserver |% {
	$serverName = $_.servername
	$servername
	
	get-content  New.dsn |%{ if ($_ -like '*WSID*') {"WSID=$servername" }else{$_} } | out-file "\\$($_.ServerNAme)\c$\Path\to\newdsn"

	$command = "cmd /c dsmaint config /user:$username /pwd:$password /dsn:$dsnfilename > c:\dsm_config.log"
	$process = [WMICLASS]"\\$serverName\ROOT\CIMV2:win32_process"
	$result = $process.Create($command)
	Start-Sleep -seconds 10
	"Arret dépendant"
	$depsvc = Get-Service -ComputerName $serverName  -name IMAService -dependentservices | Select -Property Name
	$depsvc | %{
		$svc = Get-Service -ComputerName $serverName  -name $_.Name 
		$svc.Stop()
		while($svc.status -ne "Stopped"){
			$svc = Get-Service -ComputerName $serverName  -name $svc.NAme
			Start-Sleep -seconds 1
		}
	}
	"Arret IMA"
	$service = Get-Service -ComputerName $serverName -name IMAService
	$service.stop()
	while($service.status -ne "Stopped"){
	   $service = Get-Service -ComputerName $serverName -name IMAService
	   Start-Sleep -seconds 1
	}
	
	"Relance IMA"
	$service.start()
	while($service.status -ne "Running"){
	   $service = Get-Service -ComputerName $serverName -name IMAService
	   Start-Sleep -seconds 1
	}
 
	"Relance dependant"
	$depsvc | %{
		$svc = Get-Service -ComputerName $serverName  -name $_.Name 
		$svc.Start()
		while($svc.status -ne "Running"){
			$svc = Get-Service -ComputerName $serverName  -name $svc.NAme
			Start-Sleep -seconds 1
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *