Hello Everyone,
Hope you are doing great, I am just a beginner at Powershell please help me out with the below requirements:
Aim is to convert a normal time consuming powershell script to PS Workflow using parallel techniques.
The PS Script basically reboots a list of servers based on checking 3 important conditions,as following :
#imports a list of servers $CIReport=Import-Csv D:\servers.csv do Foreach ($Computer in $CIReport) { #Checks below conditions #condition 1 #-------------------------------------------------- $CBSRebootPend = $null # Making registry connection to the local/remote computer $RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine",$Computer.CI) # Query WUAU from the registry $RegWUAU = $RegCon.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\") $RegWUAURebootReq = $RegWUAU.GetSubKeyNames() $WUAURebootReq = $RegWUAURebootReq -contains "RebootRequired" # Query PendingFileRenameOperations from the registry $RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\") $RegValuePFRO = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null) # Closing registry connection $RegCon.Close() #-------------------------------------------------- #condition 2 #-------------------------------------------------- # Determine SCCM 2012 Client Reboot Pending Status # To avoid nested 'if' statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0 $CCMClientSDK = $null $CCMSplat = @{ NameSpace='ROOT\ccm\ClientSDK' Class='CCM_ClientUtilities' Name='DetermineIfRebootPending' ComputerName=$Computer.CI ErrorAction='SilentlyContinue' } $CCMClientSDK = Invoke-WmiMethod @CCMSplat If ($CCMClientSDK) { If ($CCMClientSDK.ReturnValue -ne 0) { Write-Warning "Error: DetermineIfRebootPending returned error code $($CCMClientSDK.ReturnValue)" }#End If ($CCMClientSDK -and $CCMClientSDK.ReturnValue -ne 0) If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) { $SCCM = $true }#End If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) }#End If ($CCMClientSDK) Else { $SCCM = $null } #------------------------------------------------------- if($WUAURebootReq -eq "True" -and $SCCM -eq "True") { Restart-Computer -ComputerName $Computer -Force } else { #repeat the loop } while("End of servers in the list")
Basically this does the job correctly but it takes huge time ,Kindly help me out transforming this with parallelisms using PSWorkflow model.
I would appreciate any suggestions on it..
Thanks in advance