agent.ps1 963 B

12345678910111213141516171819
  1. # runs in the VM's logged on session (scheduled at logon by install_agent.ps1): every *.ps1 that winvm.sh run drops
  2. # into \\10.0.2.4\qemu\cmd is executed once, its output goes to \\10.0.2.4\qemu\out\<name>.txt and <name>.done marks
  3. # the end. In the user session, not a service, so programs it starts get the desktop
  4. $share = '\\10.0.2.4\qemu'
  5. New-Item -ItemType Directory -Force "$share\cmd", "$share\out" | Out-Null
  6. while ($true) {
  7. Get-ChildItem "$share\cmd" -Filter *.ps1 -ErrorAction SilentlyContinue | ForEach-Object {
  8. $name = $_.BaseName
  9. $script = "$env:TEMP\agent_$name.ps1"
  10. Move-Item $_.FullName $script -Force
  11. try {
  12. & powershell -NoProfile -ExecutionPolicy Bypass -File $script *> "$share\out\$name.txt"
  13. } catch {
  14. $_ | Out-File -Append "$share\out\$name.txt"
  15. }
  16. New-Item -ItemType File -Force "$share\out\$name.done" | Out-Null
  17. }
  18. Start-Sleep -Milliseconds 500
  19. }