########## BEGIN SCRIPT HEADER ########## # POST AUTOMATION CLEANUP DIRECTORY SETUP SCRIPT # Author: Anthony Marino # Version: V1.0.0 # Date: 9/23/2015 ########## END SCRIPT HEADER ########## ##### REQUIREMENTS ##### # Powershell execution policy must be set to unrestricted, bypass or remote signed. # You must specify the location of variables.xml, using the -VariableFiles parameter.\ Param( [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$VariablesFile, [Parameter(Position=2, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$Directory ) # Import variables.xml $xml = [XML](Get-Content $VariablesFile) # Transcode variables $PSM = $XML.Variables.AutomationSettings.WindowsPSMPath # Import the Windows PSM Import-Module $PSM -Force # Send completion email IF (($xml.Variables.Email.EmailTo) -ne "") { $Hostname = $xml.Variables.General.ServerName $Errors = (Get-Content c:\Windows\Temp\DPAutomationErrors.log -ErrorAction SilentlyContinue) DPLog -Type INFO -Message "OPTION TO SEND EMAIL DETECTED." DPSendEmail -To ($xml.Variables.Email.EmailTo) -Subject "Automated Server Setup Complete - Hostname: $Hostname" -Body "The automated server setup on hostname: $Hostname is complete. Attached is the deployment log for reference. If there were any errors, they will be reported below: $Errors" -Attachment "C:\Windows\Temp\DPAutomation.log" } ELSE { DPLog -Type INFO -Message "OPTION TO SEND EMAIL NOT DETECTED." } REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d Complete /f | Out-Null # Remove autoresume DPRemoveAutoResumeNoLogon # PS transcript IF (($xml.Variables.AutomationSettings.EnablePSTranscript) -eq $true) { $Date = (get-date -Format MMddyyyy_HHMMSS) $Filename = "C:\Windows\Temp\PSTranscript-$Date.txt" DPLog -Type INFO -Message "STOPPING POWERSHELL TRANSCRIPT." Stop-Transcript } # Remove the directory Remove-Item $Directory -Force -Recurse