I think this is worth noting for me creating a custom solution for Sandboxing an Environment full of domain admins.
Here are the interop’s if you need them, place them in the $dllpath that you choose.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host #Must run in x32 due to LoadAsm and the MSTSCfile #Define Butten Click Function $dllpath = 'C:\mstsc' [system.reflection.Assembly]::LoadFrom("$dllpath\AxInterop.MSTSCLib.dll") [system.reflection.Assembly]::LoadFrom("$dllpath\MSTSCLib.dll") $rdp = New-Object AxMSTSCLib.AxMsRdpClient6NotSafeForScripting [System.Management.Automation.ScriptBlock]$handleconnection = { # switch panels Write-Host "TADA!" #to stop run $timer.stop() #cleanup Unregister-Event thetimer } Function DisplayHelloWorldText{ $Form.Controls.Add($Label) $rdp.Name = "MyPowerShellRDP" $rdp.Enabled = "true" $ScreenBounds = [Windows.Forms.SystemInformation]::VirtualScreen $rdp.DesktopWidth = $ScreenBounds.Width $rdp.DesktopHeight = $ScreenBounds.Height $rdp.AdvancedSettings2.DisplayConnectionBar = 'true' $rdp.AdvancedSettings2.DisplayConnectionBar = 'true' $rdp.AdvancedSettings2.EnableCredSspSupport = "true" $rdp.RemoteProgram.RemoteProgramMode = 'true' $rdp.AdvancedSettings7.SmartSizing = 'true' $rdp.AdvancedSettings7.PublicMode = 'false' $rdp.AdvancedSettings7.AuthenticationLevel = 0 register-objectEvent -InputObject $rdp -EventName "OnConnected" -Action { Write-Host "<TIMER>" } $rdp.ConnectingText = 'Connecting...' $rdp.DisconnectedText = "Disconnected" $rdp.Server = "PutServerNameHere" $rdp.UserName = "" $rdp.AdvancedSettings2.RDPPort = "3389" $rdp.AdvancedSettings2.ClearTextPassword = "" $rdp.Connect() $timer = new-object timers.timer $action = {write-host "Timer Elapse Event: $(get-date -Format ‘HH:mm:ss’)"} $timer.Interval = 3000 #3 seconds #Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier thetimer -Action $handleconnection #$timer.start() #to stop run #$timer.stop() #cleanup #Unregister-Event thetimer } Function SpawnApp{ $rdp.RemoteProgram.ServerStartProgram("cmd.exe", "", "%SYSTEMROOT%", 'True', "", 'False') $rdp.RemoteProgram.ServerStartProgram("calc.exe", "", "%SYSTEMROOT%", 'True', "", 'False') } Add-Type -AssemblyName System.Windows.Forms $Form = New-Object system.Windows.Forms.Form $Form.Text = "My simple Form" $Label = New-Object System.Windows.Forms.Label $Label.Text = "This form is very simple." $Label.AutoSize = $True $Form.Controls.Add($Label) #Create button $Button1 = new-object System.Windows.Forms.Button $Button1.Location = new-object System.Drawing.Size(50, 50) $Button1.Size = new-object System.Drawing.Size(80,20) $Button1.Text = "Button" $Button1.Add_Click({DisplayHelloWorldText}) $Form.Controls.Add($Button1) #Create button $Button2 = new-object System.Windows.Forms.Button $Button2.Location = new-object System.Drawing.Size(50, 70) $Button2.Size = new-object System.Drawing.Size(80,20) $Button2.Text = "Spawn" $Button2.Add_Click({SpawnApp}) $Form.Controls.Add($Button2) $rdp.Dock = 'Fill' $Form.Controls.Add($rdp) $Form.Add_Shown({$Form.Activate()}) $Form.ShowDialog() |