I have a Hyper-V VM to which I copy files from and to the Host machine. Then I start a scheduled task on the VM which starts an application for which I log certain data. While the app is running I poll for the status of the scheduled task to check upon the status of the task using the below code:
$password= "password" | ConvertTo-SecureString -asPlainText -Force; $username = "name";$credential = New-Object System.Management.Automation.PSCredential($username,$password);Invoke-Command -VMName INSTANCE_ID -Credential $credential -ScriptBlock { $timer = [Diagnostics.Stopwatch]::StartNew(); $timeout = 2000; while (((Get-ScheduledTask -TaskName 'ID_Logging_Task').State -eq 'Running') -and ($timer.Elapsed.TotalSeconds -lt $timeout)) { Write-Verbose -Message 'Waiting on scheduled task...'; Start-Sleep -Seconds 3; } $timer.Stop(); }
Now while this app is running I want to disconnect internet connectivity for the VM(as if internet is available the app logs certain data which adds to a lot of noise) but I still want to be able to poll for my scheduled tasks status. I am okay with turning the internet off permanently as long as I am able to copy files to and from the VM and run ps1 scripts on it via a python script running on the Host machine. Please tell me if this is possible and how.