From 2c208062452b2e289a0b15630348538e1754dcca Mon Sep 17 00:00:00 2001 From: Dmitry Teselkin Date: Thu, 21 Mar 2013 17:26:49 +0400 Subject: [PATCH] Userdata script updated to support computer renaming functionality --- conductor/data/init.ps1 | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/conductor/data/init.ps1 b/conductor/data/init.ps1 index 620792c..12c2453 100644 --- a/conductor/data/init.ps1 +++ b/conductor/data/init.ps1 @@ -3,12 +3,34 @@ $WindowsAgentConfigBase64 = '%WINDOWS_AGENT_CONFIG_BASE64%' $WindowsAgentConfigFile = "C:\Keero\Agent\WindowsAgent.exe.config" +$NewComputerName = '%INTERNAL_HOSTNAME%' + +$RestartRequired = $false + Import-Module CoreFunctions -Stop-Service "Keero Agent" -Backup-File $WindowsAgentConfigFile -Remove-Item $WindowsAgentConfigFile -Force -ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile -Exec sc.exe 'config','"Keero Agent"','start=','delayed-auto' -Start-Service 'Keero Agent' -Write-Log 'All done!' \ No newline at end of file +if ( $WindowsAgentConfigBase64 -ne '%WINDOWS_AGENT_CONFIG_BASE64%' ) { + Write-Log "Updating Keero Windows Agent." + Stop-Service "Keero Agent" + Backup-File $WindowsAgentConfigFile + Remove-Item $WindowsAgentConfigFile -Force + ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile + Exec sc.exe 'config','"Keero Agent"','start=','delayed-auto' + Write-Log "Service has been updated." +} + +if ( $NewComputerName -ne '%INTERNAL_HOSTNAME%' ) { + Write-Log "Renaming computer ..." + Rename-Computer -NewName $NewComputerName | Out-Null + Write-Log "New name assigned, restart required." + $RestartRequired = $true +} + +Write-Log 'All done!' +if ( $RestartRequired ) { + Write-Log "Restarting computer ..." + Restart-Computer -Force +} +else { + Start-Service 'Keero Agent' +}