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     , to execute deployment on farms          Deploy.ps1     , to show this help file.     “ } function RemoteZetaDeployment($computerName) {       “Remote Zeta Deployment ” + $computerName } ## Main Program ## ## Parameters ##    config  : path to NLB configuration file ##    help    : show help file ## if($config -ne $null) {     write-host “Starting”     [xml] $nlb = get-content $config     #Ensures all node are started     write-host (get-date) “Ensures all nodes are started.”     $nlb.nodes.nodeinfo | foreach-object {          ControlNLBHost $_.dedicatedIP “start”     }     # DrainStop and Start each node. Wait for converged status before continuing to the next operation.     $nlb.nodes.nodeinfo | foreach-object {                  $colComputer = get-WMI-NLB $_.dedicatedIP          if($colcomputer.StatusCode -eq 1007 -or $colcomputer.StatusCode -eq 1008 )          {              write-host (get-date) “Draining ” $colcomputer.ComputerName                          ControlNLBHost $strComputer “stop”                        write-host (get-date) “  Draining completed.”                              write-host (get-date) “Check converging ”              WaitNLB-Converging $nlb              write-host (get-date) “   Converging completed”                           write-host (get-date) “Execute deployment”              RemoteZetaDeployment $_.dedicatedIP              write-host (get-date) “Deployment completed”                                          write-host (get-date) “Restarting NLB node ” $colcomputer.ComputerName                         ControlNLBHost $strComputer “start”              write-host (get-date) “  Restarting is completed.”                          }                  write-host (get-date) “  ComputerName: “ $colcomputer.ComputerName                      write-host (get-date) “  StatusCode: “ (DisplayNodeStatus $colcomputer.StatusCode)                               }     write-host (get-date) “Completed”     } else {    Help }

Avatar
Riwut Libinuko
Sr. Cloud Solution Architect

My research interests include distributed robotics, mobile computing and programmable matter.

comments powered by Disqus

Related