Skip to content

Instantly share code, notes, and snippets.

@Stanislasss
Created April 23, 2020 17:09
Show Gist options
  • Select an option

  • Save Stanislasss/ae380b9d06a1e43a6d78dfa0b920de87 to your computer and use it in GitHub Desktop.

Select an option

Save Stanislasss/ae380b9d06a1e43a6d78dfa0b920de87 to your computer and use it in GitHub Desktop.
$NodesList = [Environment]::GetEnvironmentVariable('NODES_LIST', 'User').Split(",")
$NodesList | ForEach-Object {
# Generate cached credentials for RDP session
cmdkey.exe /generic:$_ /user:MYDOMAIN\MYUSER /pass:"MYPASSWORD"
write-Output "Activating node $_ through RDP session..."
$app = Start-Process -FilePath C:\Windows\System32\mstsc.exe -ArgumentList "/v:$_" -PassThru
Start-Sleep -s 60
# Deleting cached credentials for security purpose
cmdkey.exe /del:$_
$app | Stop-Process
write-Output "Stopped RDP connection to node $_, the node should now be online"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment