From ee28e6f13263d62a1ad4fc607c410fd8fd1df808 Mon Sep 17 00:00:00 2001 From: dyoder Date: Mon, 22 Jun 2020 10:57:58 -0400 Subject: [PATCH] update --- Install-ManagementAgent.ps1 | 54 ++++++++++++++++++++++++++----------- Start-WakeOnLAN.ps1 | 13 +++++++++ 2 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 Start-WakeOnLAN.ps1 diff --git a/Install-ManagementAgent.ps1 b/Install-ManagementAgent.ps1 index ca9100a..67a3190 100644 --- a/Install-ManagementAgent.ps1 +++ b/Install-ManagementAgent.ps1 @@ -5,13 +5,31 @@ param( [string]$AGENT_FILENAME='EmberkomAgentSetup.exe' ) +## Get a temporary path +$TEMP = [System.IO.Path]::GetTempPath() + +## Setup log file and function to write to it +$LOGFILE = "{0}EmberkomAgentSetup_{1}.log" -f $TEMP, $(Get-Date -Format "yyyyMMddHHmmss") +If (! (Test-Path $LOGFILE) ) { New-Item -Path $LOGFILE -ItemType File } +Function Write-Log([string]$message) +{ + $entry = "{0} : {1}" -f $(Get-Date -Format "yyyyMMddHHmmss"), $Message + Add-Content -Path $LOGFILE -Value $entry +} +Write-Log "Agent installation script has started" + ## Immediately delete this script from disk -Try { Remove-Item $MyINvocation.InvocationName -Force } -Catch { Write-Output "This script tried to delete itself but failed!" } +$THIS_SCRIPT = $MyInvocation.InvocationName +Write-Log "Deleting this script: ${THIS_SCRIPT}" +Try { Remove-Item $MyInvocation.InvocationName -Force } +Catch { Write-Log "This script tried to delete itself but failed!" } + +Write-Log "CUSTOMER_ID: ${CUSTOMER_ID}" +Write-Log "SOFTWARE_ID: ${SOFTWARE_ID}" ## Build the path for $AGENT_INSTALLER -$TEMP = [System.IO.Path]::GetTempPath() $AGENT_INSTALLER = "${TEMP}\${AGENT_FILENAME}" +Write-Log "Agent installer will be saved to: ${AGENT_INSTALLER}" ## Make sure the CUSTOMER_ID is specified If ( $CUSTOMER_ID ) @@ -25,30 +43,36 @@ If ( $CUSTOMER_ID ) ## Delete $AGENT_INSTALLER if it already exists If ( Test-Path $AGENT_INSTALLER ) { + Write-Log "Deleting previous agent installer: ${AGENT_INSTALLER}" Try { Remove-Item $AGENT_INSTALLER -Force } - Catch { Write-Output $_.Exception.Message } + Catch { Write-Log $_.Exception.Message } } - ## Setup security and certificate parameters to download from untrusted sources - [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} - [Net.ServicePointManager]::SecurityProtocol = - [Net.SecurityProtocolType]::Tls12 -bor ` - [Net.SecurityProtocolType]::Tls11 -bor ` - [Net.SecurityProtocolType]::Tls + ### Setup security and certificate parameters to download from untrusted sources + #[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} + #[Net.ServicePointManager]::SecurityProtocol = + # [Net.SecurityProtocolType]::Tls12 -bor ` + # [Net.SecurityProtocolType]::Tls11 -bor ` + # [Net.SecurityProtocolType]::Tls ## Download the agent installer + Write-Log "Downloading agent installer from: ${AGENT_URL}" Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) } - Catch { Write-Output $_.Exception.Message ; Exit } + Catch { Write-Log $_.Exception.Message ; Exit } ## Install the agent + Write-Log "Begin installing agent" Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait } - Catch { Write-Output $_.Exception.Message } + Catch { Write-Log $_.Exception.Message } ## Remove the agent installer If ( Test-Path $AGENT_INSTALLER ) { + Write-Log "Deleting agent installer: ${AGENT_INSTALLER}" Try { Remove-Item -Path $AGENT_INSTALLER -Force } - Catch { Write-Output $_.Exception.Message } + Catch { Write-Log $_.Exception.Message } } - } Else { Write-Output "The agent is already installed on this endpoint." } -} Else { Write-Output "No CUSTOMER_ID was specified!" } + + Write-Log "Agent installation script has finished" + } Else { Write-Log "The agent is already installed on this endpoint." } +} Else { Write-Log "No CUSTOMER_ID was specified!" } diff --git a/Start-WakeOnLAN.ps1 b/Start-WakeOnLAN.ps1 new file mode 100644 index 0000000..13e0a95 --- /dev/null +++ b/Start-WakeOnLAN.ps1 @@ -0,0 +1,13 @@ +## Target MAC address +$Mac = "f8:bc:12:83:ce:3e" + +$MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"} +[Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray * 16) +Try +{ + $UdpClient = New-Object System.Net.Sockets.UdpClient + $UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7) + $UdpClient.Send($MagicPacket,$MagicPacket.Length) + $UdpClient.Close() +} +Catch { Write-Output $_.Exception.Message } \ No newline at end of file