Merge "Userdata script updated to support computer renaming functionality"
This commit is contained in:
@@ -3,12 +3,34 @@
|
|||||||
$WindowsAgentConfigBase64 = '%WINDOWS_AGENT_CONFIG_BASE64%'
|
$WindowsAgentConfigBase64 = '%WINDOWS_AGENT_CONFIG_BASE64%'
|
||||||
$WindowsAgentConfigFile = "C:\Keero\Agent\WindowsAgent.exe.config"
|
$WindowsAgentConfigFile = "C:\Keero\Agent\WindowsAgent.exe.config"
|
||||||
|
|
||||||
|
$NewComputerName = '%INTERNAL_HOSTNAME%'
|
||||||
|
|
||||||
|
$RestartRequired = $false
|
||||||
|
|
||||||
Import-Module CoreFunctions
|
Import-Module CoreFunctions
|
||||||
|
|
||||||
|
if ( $WindowsAgentConfigBase64 -ne '%WINDOWS_AGENT_CONFIG_BASE64%' ) {
|
||||||
|
Write-Log "Updating Keero Windows Agent."
|
||||||
Stop-Service "Keero Agent"
|
Stop-Service "Keero Agent"
|
||||||
Backup-File $WindowsAgentConfigFile
|
Backup-File $WindowsAgentConfigFile
|
||||||
Remove-Item $WindowsAgentConfigFile -Force
|
Remove-Item $WindowsAgentConfigFile -Force
|
||||||
ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile
|
ConvertFrom-Base64String -Base64String $WindowsAgentConfigBase64 -Path $WindowsAgentConfigFile
|
||||||
Exec sc.exe 'config','"Keero Agent"','start=','delayed-auto'
|
Exec sc.exe 'config','"Keero Agent"','start=','delayed-auto'
|
||||||
Start-Service 'Keero Agent'
|
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!'
|
Write-Log 'All done!'
|
||||||
|
if ( $RestartRequired ) {
|
||||||
|
Write-Log "Restarting computer ..."
|
||||||
|
Restart-Computer -Force
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Start-Service 'Keero Agent'
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user