MondayUpdates.psm1
<#
.NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.165 Generated on: 8/20/2019 10:11 AM Generated by: Craig Moore (McMurdo Sr Systems Administrator) Organization: United States Antarctic Program -------------------------------------------------------------------------------- .DESCRIPTION Script generated by PowerShell Studio 2019 #> <# =========================================================================== Created on: 8/6/2019 12:20 PM Created by: Craig Moore (McMurdo Sr Systems Administrator) Organization: United States Antarctic Program Filename: MondayUpdates.psm1 ------------------------------------------------------------------------- Module Name: MondayUpdates =========================================================================== #> <# .EXTERNALHELP MondayUpdates.psm1-Help.xml #> function Get-PendingReboot { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = 'Archive ile location for the Windows Updates Checklist. Date will be added after saving')] [System.IO.FileInfo] $Path, [Parameter(Mandatory = $true)] [System.IO.FileInfo] $UpdateChecklist, [switch] $Show ) # Prepare to move checklist to archive folder and rename $filename = [io.path]::GetFileNameWithoutExtension($UpdateChecklist) $ext = [io.path]::GetExtension($UpdateChecklist) $NewName = "$filename $(get-date -Format yyyy-MM-dd)$ext" $Path = "$Path$NewName" # Cleanup archive if script is run on the same day Remove-Item -Path $Path -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 # Copy checklist with date to archive Copy-Item -Path $UpdateChecklist -Destination $Path Start-Sleep -Seconds 2 # Add the date inside the Sheet $Date = "Date:" $Date, (Get-Date -Format "MMMM dd, yyyy") -join " " | Export-Excel -Path $Path -WorksheetName "Systems Maintenance Checklist" -StartColumn 10 # Get servers from Windows Updates Checklist.xlsx $Servers = Import-Excel -Path $Path -WorksheetName "Systems Maintenance Checklist" -StartRow 7 | ForEach-Object { Test-PendingReboot -ComputerName $_.Server -SkipPendingFileRenameOperationsCheck -ErrorAction SilentlyContinue } # Create tab Pending Reboot showing systems that need rebooting $Servers | Export-Excel -Path $Path -TableName "PendingReboot" -AutoSize -FreezePane 3 -TableStyle Medium16 -Title "Windows Pending Reboot Server Updates" -TitleBold -TitleSize 20 -WorksheetName "Pending Reboot" -ErrorAction SilentlyContinue # Open Windows Updates Checklist.xlsx when done if ($Show) { Invoke-Item $Path } } |