SharePoint 2010: Powershell for deployment in large farm
param ($config) <################################################### # PS # ####################################################> ## Global params $NLB_CLASS=“MicrosoftNLB_Node” $NLB_NS=“root\MicrosoftNLB” $NLB_FileConfig = “c:\nlb.xml” # For testing purpose only ## ## Display Readable Status Node ## Params : (int) returnValue ## function DisplayNodeStatus($returnValue) { switch($returnValue) { 1000 {“ Success.”;break} 1001 {“ Cluster mode is already stopped/started, or traffic handling is already made.”;break} 1002 {“ Cluster mode stop or start operation interrupted connection draining process.”;break} 1003 {“ Cluster mode can not be started due to configuration problems on the target hosts.”;break} 1004 {“ Port number not found among port rules.”;break} 1005 {“ Cluster mode is stopped on the host.”;break} 1006 {“ Cluster is converging.”;break} 1007 {“ Cluster or host converged successfully.”;break} 1008 {“ Host is converged as default host.”;break} 1009 {“ Host is draining after drainstop command.”;break} default {“ Unkown return ($returnValue).”} } } # # get-WMI-NLB ComputerName # # ComputerName , Dedicated IP or hostname of the cluster member. function get-WMI-NLB($computerName) { return get-wmiObject -class $NLB_CLASS -namespace $NLB_NS -comp $computerName } # # ControlNLBHost ComputerName [start|stop] # # ComputerName , Dedicated IP or hostname of the cluster member. function ControlNLBHost($computerName,$operation) { $colComputer = get-WMI-NLB $computerName switch($operation) { “start” { if($colComputer.StatusCode -eq 1007 -or $colComputer.StatusCode -eq 1008) { break; } $a = $colComputer.Start() ; while(!($colcomputer.StatusCode -eq 1007 -or $colcomputer.StatusCode -eq 1008)) { write-progress -Activity “Starting…” -Status “Please wait.” $colcomputer = get-WMI-NLB $computerName start-sleep 2 } write-progress -Activity “Starting…” -Completed -Status “Starting completed.” break } “stop” { if($colComputer.StatusCode -eq 1005) { break; } $a = $colComputer.DrainStop(); write-host (get-date) “Draining” $comp.ComputerName; while($colcomputer.StatusCode -ne 1005) { write-progress -Activity “Draining…” -Status “Please wait.” $colcomputer = get-WMI-NLB $computerName start-sleep 2 } write-progress -Activity “Draining…” -Completed -Status “Draining completed.“ break } } } function WaitNLB-Converging($xmlNlb) { $isConverging = $true while($isConverging) { $isConverging = $false $xmlNlb.nodes.nodeinfo | foreach-object { $colComputer = get-WMI-NLB $_.dedicatedIP if($colComputer.Status -eq 1006) { $isConverging = $true break } start-sleep 2 } } } function Help() { “ Usage : Deploy.ps1 -config