<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: all windows templates patching in a datacenter in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289989#M80541</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you are using the pipeline in the $tasks foreach loop to capture the results, you should make sure that nothing else is placed on the pipeline.&lt;/P&gt;&lt;P&gt;The Stop-VMGuest, Stop-VM and Start-VM cmdlets place objects in the pipeline.&lt;/P&gt;&lt;P&gt;Redirect those to Out-Null (see attached file).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: line breaks and indentation make a file so much easier to read (and debug)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Aug 2020 12:04:11 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2020-08-31T12:04:11Z</dc:date>
    <item>
      <title>all windows templates patching in a datacenter</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289988#M80540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have finally completed the below script to do windows updates on all templates in a datacenter using a DHCP vLan. Thanks for your support.&lt;/P&gt;&lt;P&gt;I need one fix in the script output. After updating windows I am writing output in a csv but that is not writing in correcting format. Every VMs output is written twice and leaving blank rows between every vms output. Sample output&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://communities.vmware.com/t5/image/serverpage/image-id/22650iAE090A2E380523B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="_jivemacro_uid_15988665356655067 jive_macro_code jive_text_macro" data-renderedposition="1580_8_1215_3600" jivemacro_uid="_15988665356655067"&gt;&lt;P&gt;$location=Get-Location&lt;/P&gt;&lt;P&gt;$CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'&lt;/P&gt;&lt;P&gt;$logfilelocation= "$location\$($CurrentDate)logfile.txt"&lt;/P&gt;&lt;P&gt;$alltemplatesexportpath="$location\$($CurrentDate)-templateswindows.csv"&lt;/P&gt;&lt;P&gt;$Outputfile = "$location\AllTemplatepatchstatusreport.csv as on dated $($CurrentDate).csv" &lt;/P&gt;&lt;P&gt;$csvFiles = @()&lt;/P&gt;&lt;P&gt;Write-Host "Enter Administrator Credentials for logging into templates" -ForegroundColor Yellow&lt;/P&gt;&lt;P&gt;$cred=Get-Credential&lt;/P&gt;&lt;P&gt;Start-Transcript -Path $logfilelocation -NoClobber -Force -Confirm:$false&lt;/P&gt;&lt;P&gt;$script = @' &lt;/P&gt;&lt;P&gt;$report = @()&lt;/P&gt;&lt;P&gt;$ErrorActionPreference = "SilentlyContinue"&lt;/P&gt;&lt;P&gt;If ($Error) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Error.Clear()&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;$updatesession=New-Object -ComObject Microsoft.update.session &lt;/P&gt;&lt;P&gt;$Criteria="IsInstalled=0 and Type=Software and IsHidden=0"&lt;/P&gt;&lt;P&gt;$searchresult=$updateSession.CreateupdateSearcher().Search("IsInstalled=0 and Type='Software' and IsHidden=0").Updates &lt;/P&gt;&lt;P&gt;$report = if(-not $searchresult.Count){&lt;/P&gt;&lt;P&gt;New-Object -TypeName PSObject -property @{&lt;/P&gt;&lt;P&gt;KB = ''&lt;/P&gt;&lt;P&gt;InstallStatus = 'There are no applicable updates for this computer.'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else{&lt;/P&gt;&lt;P&gt;$pendingdownloads=$searchresult | Where-Object {$_.IsDownloaded -eq $false}&lt;/P&gt;&lt;P&gt;if(($pendingdownloads |Select-Object IsDownloaded).count -ne '0'){&lt;/P&gt;&lt;P&gt;$downloadercall=$updatesession.CreateUpdateDownloader()&lt;/P&gt;&lt;P&gt;$downloadercall.Updates=New-Object -ComObject Microsoft.update.updatecoll&lt;/P&gt;&lt;P&gt;foreach($pendingdownload in $pendingdownloads){&lt;/P&gt;&lt;P&gt;[void]$downloadercall.Updates.add($pendingdownload)&lt;/P&gt;&lt;P&gt;$downloadercall.Download() |Out-Null&lt;/P&gt;&lt;P&gt;[void]$downloadercall.Updates.RemoveAt(0)&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;$updatesession=New-Object -ComObject Microsoft.update.session&lt;/P&gt;&lt;P&gt;$Criteria="IsInstalled=0 and Type=Software and IsHidden=0"&lt;/P&gt;&lt;P&gt;$searchresult=$updateSession.CreateupdateSearcher().Search("IsInstalled=0 and Type='Software' and IsHidden=0").Updates&lt;/P&gt;&lt;P&gt;$downloadedupdates = $searchresult&amp;nbsp; | Where-Object {$_.IsDownloaded -eq $true}&lt;/P&gt;&lt;P&gt;$updatercall=$updatesession.CreateUpdateInstaller()&lt;/P&gt;&lt;P&gt;$updatercall.Updates= New-Object -ComObject Microsoft.update.updatecoll&lt;/P&gt;&lt;P&gt;foreach($singleupdate in $downloadedupdates){&lt;/P&gt;&lt;P&gt;[void]$updatercall.Updates.add($singleupdate)&lt;/P&gt;&lt;P&gt;$installstatus=$updatercall.install()&lt;/P&gt;&lt;P&gt;[void]$updatercall.Updates.RemoveAt(0)&lt;/P&gt;&lt;P&gt;New-Object -TypeName PSObject -property @{&lt;/P&gt;&lt;P&gt;KB = &amp;amp;{$kbnumb=$singleupdate.Title; $kbnumb.Substring($kbnumb.IndexOf("KB")).Trimend(")")}&lt;/P&gt;&lt;P&gt;InstallStatus = &amp;amp;{&lt;/P&gt;&lt;P&gt;if($installstatus.ResultCode -eq '2'){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'KB Installed'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;elseif($installstatus.ResultCode -eq '3'){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'KB Install Succeeded with errors'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;elseif($installstatus.ResultCode -eq '4'){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Kb Failed to install'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;elseif($installstatus.ResultCode -eq '5'){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'KBAborted'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;elseif (-not $installstatus.ResultCode){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'KB Failed to Download'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;$report | ConvertTo-Csv -NoTypeInformation&lt;/P&gt;&lt;P&gt;'@&lt;/P&gt;&lt;P&gt;$tasks = @()&lt;/P&gt;&lt;P&gt;$alltemplates=Get-Datacenter&amp;nbsp; | Get-Template&amp;nbsp;&amp;nbsp; |Select-Object @{N='Name';E={$_.Name}},@{N="Portgroup";E={((Get-View -Id $_.ExtensionData.Network).name)}},@{N="vCenter";E={([System.Net.Dns]::GetHostEntry($_.Uid.Split(“:”)[0].Split(“@”)[1])).HostName}}&lt;/P&gt;&lt;P&gt;$alltemplates|Export-Csv -Path $alltemplatesexportpath -NoTypeInformation -NoClobber -UseCulture&lt;/P&gt;&lt;P&gt;foreach($singletemplate in $alltemplates){&lt;/P&gt;&lt;P&gt;Write-Host "Marking Template Name $($singletemplate.Name) to VM"&lt;/P&gt;&lt;P&gt;Set-Template -Template $singletemplate.Name -ToVM -Confirm:$false |fl&lt;/P&gt;&lt;P&gt;$templatevm= Get-VM $singletemplate.Name&lt;/P&gt;&lt;P&gt;if(-not $templatevm.Name){&lt;/P&gt;&lt;P&gt;Write-Host "Setting Template $($singletemplate.Name) to VM Failed Moving to Next Template"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else{&lt;/P&gt;&lt;P&gt;Write-Host "Collecting DHCP PortGroup Name for Vlanid 2067 from VMhost $($templatevm.VMHost)"&lt;/P&gt;&lt;P&gt;$dhcpportgroup=Get-VirtualPortGroup -VMHost $templatevm.VMHost |?{$_.ExtensionData.config.DefaultPortConfig.Vlan.VlanId -eq '2067'}&lt;/P&gt;&lt;P&gt;Write-Host "Collecting Network Adapter for $($templatevm.Name)" &lt;/P&gt;&lt;P&gt;$nic=Get-NetworkAdapter -VM $templatevm.Name&lt;/P&gt;&lt;P&gt;Write-Host "Adding Network Adapter to VM $($templatevm.Name) if not Present" &lt;/P&gt;&lt;P&gt;if($nic -eq $null){&lt;/P&gt;&lt;P&gt;New-NetworkAdapter -VM $templatevm.Name -Portgroup $dhcpportgroup -Type Vmxnet3 -StartConnected -Confirm:$false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else{&lt;/P&gt;&lt;P&gt;Write-Host "Changing Portgroup to $($dhcpportgroup.Name) to VM $($templatevm.Name)" &lt;/P&gt;&lt;P&gt;Get-NetworkAdapter -VM $templatevm.Name |Set-NetworkAdapter -Portgroup $dhcpportgroup -Confirm:$false |fl&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Starting VM $($templatevm.Name) and wait in loop till GuestOperationsReady is true " &lt;/P&gt;&lt;P&gt;Start-VM -VM $templatevm.Name -Confirm:$false |fl&lt;/P&gt;&lt;P&gt;while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){&lt;/P&gt;&lt;P&gt;Start-Sleep -Seconds 3&lt;/P&gt;&lt;P&gt;$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Updating vmtools on $($templatevm.Name) if they are Outdated"&lt;/P&gt;&lt;P&gt;if($templatevm.ExtensionData.guest.toolsversionstatus -eq 'guestToolsNeedUpgrade'){&lt;/P&gt;&lt;P&gt;$timeoutSeconds = 900&lt;/P&gt;&lt;P&gt;$start = (Get-Date)&lt;/P&gt;&lt;P&gt;$task = Get-View -Id (Update-Tools -VM $templatevm.Name -NoReboot&amp;nbsp; -RunAsync).Id&lt;/P&gt;&lt;P&gt;while((New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds -lt $timeoutSeconds -and &lt;/P&gt;&lt;P&gt;($task.Info.State -eq [VMware.Vim.TaskInfoState]::running -or&lt;/P&gt;&lt;P&gt;$task.Info.State -eq [VMware.Vim.TaskInfoState]::queued)){&lt;/P&gt;&lt;P&gt;Sleep 5&lt;/P&gt;&lt;P&gt;$task.UpdateViewData()&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if($task.Info.State -eq [VMware.Vim.TaskInfoState]::running){&lt;/P&gt;&lt;P&gt;$task.CancelTask()&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;elseif($task.Info.State -eq [VMware.Vim.TaskInfoState]::error){&lt;/P&gt;&lt;P&gt;Write-Error "Update Tools failed"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Waiting for GuestOperationsReady to be true on $($templatevm.Name)"&lt;/P&gt;&lt;P&gt;$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")&lt;/P&gt;&lt;P&gt;while($templatevm.ExtensionData.Guest.GuestOperationsReady -ne "True"){&lt;/P&gt;&lt;P&gt;Start-Sleep -Seconds 3&lt;/P&gt;&lt;P&gt;$templatevm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Performing Invoke Operation on $($templatevm.Name)"&lt;/P&gt;&lt;P&gt;$sInvoke = @{&lt;/P&gt;&lt;P&gt;VM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $templatevm.Name&lt;/P&gt;&lt;P&gt;GuestCredential=$cred&lt;/P&gt;&lt;P&gt;ScriptText&amp;nbsp;&amp;nbsp;&amp;nbsp; = $script&lt;/P&gt;&lt;P&gt;ScriptType&amp;nbsp;&amp;nbsp;&amp;nbsp; = 'Powershell'&lt;/P&gt;&lt;P&gt;RunAsync&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $true&lt;/P&gt;&lt;P&gt;Confirm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;$tasks += @{&lt;/P&gt;&lt;P&gt;VM = $templatevm.Name&lt;/P&gt;&lt;P&gt;Task = Invoke-VMScript @sInvoke&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Invoke Operation is performed on all the templates and waiting for results to be collected"&lt;/P&gt;&lt;P&gt;while($tasks.Task.State -contains 'Running'){&lt;/P&gt;&lt;P&gt;sleep 2&lt;/P&gt;&lt;P&gt;Write-Host "waiting on Invoke Operation to Complete" -ForegroundColor Yellow&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Passing tasks information to foreach loop"&lt;/P&gt;&lt;P&gt;$tasks |ForEach-Object -Process {&lt;/P&gt;&lt;P&gt;$vm=Get-VM -Name $_.VM&lt;/P&gt;&lt;P&gt;Write-Host "Stopping VM $($vm.Name) to Apply windows updates"&lt;/P&gt;&lt;P&gt;Stop-VMGuest -VM $vm.Name -Confirm:$false&lt;/P&gt;&lt;P&gt;while($vm.ExtensionData.Runtime.PowerState -ne 'poweredOff'){&lt;/P&gt;&lt;P&gt;Start-Sleep -Seconds 1&lt;/P&gt;&lt;P&gt;$vm.ExtensionData.UpdateViewData("Runtime.Powerstate")&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Starting back the VM $($vm.Name) after applying updates"&lt;/P&gt;&lt;P&gt;Start-VM -VM $vm.Name -Confirm:$false&lt;/P&gt;&lt;P&gt;$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")&lt;/P&gt;&lt;P&gt;while($vm.ExtensionData.Guest.GuestOperationsReady -ne "True"){&lt;/P&gt;&lt;P&gt;Start-Sleep -Seconds 1&lt;/P&gt;&lt;P&gt;$vm.ExtensionData.UpdateViewData("Guest.GuestOperationsReady")&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Performing Invoke operation on VM $($vm.Name) to check if all updates are installed"&lt;/P&gt;&lt;P&gt;$updatescheckscript=@'&lt;/P&gt;&lt;P&gt;$updateObject = New-Object -ComObject Microsoft.Update.Session&lt;/P&gt;&lt;P&gt;$updateSearcher = $updateObject.CreateUpdateSearcher()&lt;/P&gt;&lt;P&gt;$searchResults = $updateSearcher.Search("IsInstalled=0")&lt;/P&gt;&lt;P&gt;$timeoutValue = 1200&lt;/P&gt;&lt;P&gt;$startTime = Get-Date&lt;/P&gt;&lt;P&gt;while($searchResults.Updates.Count -ne '0' -and (New-TimeSpan -Start $startTime -End (Get-Date)).TotalSeconds -lt $timeoutValue){&lt;/P&gt;&lt;P&gt;Start-Sleep 1&lt;/P&gt;&lt;P&gt;$searchResults.Updates.Count&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if((New-TimeSpan -Start $startTime -End (Get-Date)).TotalSeconds -ge $timeoutValue) {&lt;/P&gt;&lt;P&gt;'windows update completed Partially'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else{&lt;/P&gt;&lt;P&gt;'windows update completed sucessfully'&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;'@&lt;/P&gt;&lt;P&gt;$sInvoke = @{&lt;/P&gt;&lt;P&gt;VM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $vm.Name&lt;/P&gt;&lt;P&gt;GuestCredential=$cred&lt;/P&gt;&lt;P&gt;ScriptText&amp;nbsp;&amp;nbsp;&amp;nbsp; = $updatescheckscript&lt;/P&gt;&lt;P&gt;ScriptType&amp;nbsp;&amp;nbsp;&amp;nbsp; = 'Powershell'&lt;/P&gt;&lt;P&gt;ErrorAction&amp;nbsp;&amp;nbsp; = 'SilentlyContinue'&lt;/P&gt;&lt;P&gt;Confirm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;$invokeresult=Invoke-VMScript @sInvoke&lt;/P&gt;&lt;P&gt;Write-Host "Result of invoke operation on VM $($vm.Name)"&lt;/P&gt;&lt;P&gt;Write-Host $invokeresult.ScriptOutput&lt;/P&gt;&lt;P&gt;Write-Host "Performing Stop operation on VM $($vm.Name) before converting to Template"&lt;/P&gt;&lt;P&gt;$maxCount = 3&lt;/P&gt;&lt;P&gt;$count = 0&lt;/P&gt;&lt;P&gt;while($count -lt $maxCount -and $vm.PowerState -ne 'PoweredOff' ){&lt;/P&gt;&lt;P&gt;Stop-VMGuest -VM $vm.Name -Confirm:$false&lt;/P&gt;&lt;P&gt;$count++&lt;/P&gt;&lt;P&gt;Sleep 300&lt;/P&gt;&lt;P&gt;$vm = Get-VM -Name $vm.Name&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if($vm.PowerState -ne 'PoweredOff'){&lt;/P&gt;&lt;P&gt;Stop-VM -VM $vm -Confirm:$false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Write-Host "Updating report to csv"&lt;/P&gt;&lt;P&gt;if($_.Task.State -eq 'Success'){&lt;/P&gt;&lt;P&gt;$_.Task.Result.Scriptoutput | ConvertFrom-Csv |&lt;/P&gt;&lt;P&gt;Add-Member -MemberType NoteProperty -Name VM -Value $_.VM.Name -PassThru |&lt;/P&gt;&lt;P&gt;Add-Member -MemberType NoteProperty -Name State -Value $_.Task.State -PassThru&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else{&lt;/P&gt;&lt;P&gt;New-Object -TypeName PSObject -Property @{&lt;/P&gt;&lt;P&gt;VM = $_.VM.Name&lt;/P&gt;&lt;P&gt;KB = ''&lt;/P&gt;&lt;P&gt;InstallStatus = ''&lt;/P&gt;&lt;P&gt;State = $_.Task.State&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;} | Select VM,State,KB,InstallStatus |Export-Csv -Path $Outputfile -NoTypeInformation -NoClobber -UseCulture&lt;/P&gt;&lt;P&gt;Write-Host "Saved results to csv file"&lt;/P&gt;&lt;P&gt;$csvFiles += $Outputfile&lt;/P&gt;&lt;P&gt;Write-Host "Converting Back to templates"&lt;/P&gt;&lt;P&gt;$alltemplates |ForEach-Object -Process {&lt;/P&gt;&lt;P&gt;Get-NetworkAdapter -VM $_.name |Set-NetworkAdapter -NetworkName $_.Portgroup -Confirm:$false&lt;/P&gt;&lt;P&gt;Set-VM -VM $_.Name -ToTemplate -Confirm:$false&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Stop-Transcript&lt;/P&gt;&lt;P&gt;$csvFiles+=$logfilelocation&lt;/P&gt;&lt;P&gt;$csvFiles+=$alltemplatesexportpath&lt;/P&gt;&lt;P&gt;Send-MailMessage -From "" -To "" -Subject "Template Patching Info" ` -Body "The attachment contains templates patching status after script execution" ` -Attachments $csvFiles -SmtpServer ''&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2020 09:37:58 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289988#M80540</guid>
      <dc:creator>vin01</dc:creator>
      <dc:date>2020-08-31T09:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: all windows templates patching in a datacenter</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289989#M80541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you are using the pipeline in the $tasks foreach loop to capture the results, you should make sure that nothing else is placed on the pipeline.&lt;/P&gt;&lt;P&gt;The Stop-VMGuest, Stop-VM and Start-VM cmdlets place objects in the pipeline.&lt;/P&gt;&lt;P&gt;Redirect those to Out-Null (see attached file).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: line breaks and indentation make a file so much easier to read (and debug)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2020 12:04:11 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289989#M80541</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2020-08-31T12:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: all windows templates patching in a datacenter</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289990#M80542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks LucD. Now the results are showing correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Sep 2020 04:37:20 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/all-windows-templates-patching-in-a-datacenter/m-p/2289990#M80542</guid>
      <dc:creator>vin01</dc:creator>
      <dc:date>2020-09-03T04:37:20Z</dc:date>
    </item>
  </channel>
</rss>

