PS-Windows-Install.ps1 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #Installation
  2. $InstallationToken = ''
  3. $BaseURL = ''
  4. $Hostname = hostname
  5. if(!(Test-Path HKLM:\SOFTWARE\SRM\)){
  6. $fullurl = "$BaseURL/inform/register/?hostname=$Hostname&do=newasset"
  7. $webClient = New-Object System.Net.WebClient
  8. $webClient.Headers.add('Authorization',$InstallationToken)
  9. $realtoken = $webClient.DownloadString($fullurl)
  10. }
  11. New-Item -Path HKLM:\SOFTWARE -Name SRM
  12. New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name AssetToken -Value $realtoken
  13. New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name MasterURL -Value $BaseURL
  14. New-Item "C:\Windows\SRM" -Type Directory
  15. $clientscript = "
  16. add-content -Path C:\logs.txt -Value test
  17. "
  18. Set-Content -Path C:\Windows\SRM\client.ps1 -Value $clientscript
  19. $account = Get-Credential
  20. $Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NonInteractive -NoLogo -NoProfile -File "C:\Windows\SRM\client.ps1"'
  21. $Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
  22. $Settings = New-ScheduledTaskSettingsSet
  23. $Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
  24. Register-ScheduledTask -TaskName 'SRM Poller' -InputObject $Task -User (Read-Host Username)
  25. New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name ClientSetup -Value 1