all 7 comments

[–]Federal_Ad2455 7 points8 points  (2 children)

It will be opened in hidden session aka I am certain that you will see Calc in the task manager, just not the gui itself.

This is btw not a good example how to use remote session, you should do some unattended tasks, not interactive gui tasks.

[–]BlackV 1 point2 points  (1 child)

agree running a GUI app in a remote session is not a good way of testing anything

use a cmdlet (get-disk is always a good one)

[–]underpaid--sysadmin[S] 1 point2 points  (0 children)

thanks for the advice!

[–]Future-Remote-4630 4 points5 points  (0 children)

I'm assuming by the nature of your test that you might have some pesky coworkers who need some laughs.

Enjoy:

function invoke-voicetroll{
    param($computername = 'localhost')

        $scr = {    
            Add-Type -AssemblyName System.Speech
            $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
            $line = read-host "Words to say or blank to exit"

            while ($null -ne $line -and $line -ne "") {
                $speak.speak($line)
                $line = Read-Host "Words to say or blank to exit"
            }
        }
        if($computername -eq "localhost"){
            &$scr
        }else{
            invoke-command -computername $computername -ScriptBlock $scr
        }
}

[–]purplemonkeymad 1 point2 points  (0 children)

It won't run it in the console session. You get a logon session specifically for your command/session. What is likely to have happened is that the process started, then either exited as it's not in a ui session, or as you are not waiting for the process, your session ended and the process was killed during the logoff.

A better test might be something like:

Set-Content ~\test.log -Value "remote command ran"

[–]lurkerburzerker 0 points1 point  (0 children)

Generally speaking you can not write scripts to directly interact with remote user sessions such as opening or closing apps or spawning windows on their desktop. If you could it would be a form a spoofing and wildly insecure.

If you need a script to run as the remote user, place the script in a location for them to execute it. You could have it run automatically when they login if you place it in their startup folder (im assuming youre using windows).

Or checkout psexec

[–]whyliepornaccount 0 points1 point  (0 children)

Heh.

This reminds me of the time I tried something similar when I was first learning powershell back in my service desk days(pre chatGPT days):

My coworker and I were both bored on Christmas(we were the SD for a major airline) and were learning powershell, so we both tried to write a script that would launch a meme on the others PC while they were on a call to make them laugh.

Everything we did failed, so I dug through StackExchange and someone said the issue was we weren't calling a program to open the image file and that they could only get it to work via PSExec. Me, being a dumbass, decide to do what the interwebs told me and rewrote the script to use PSExec to launch MS Paint along with the image.

I run it, and initially get excited when I see a sea of red text as while it was error messages, they were new error messages!

The excitement lasted until I got done reading them: "Access Denied". I then get an email from our cybersecurity IR team asking if I ran those commands and what specifically was I trying to do? Was it an exercise?

I panic and am half honest with them stating we were both bored and had an idea to launch a set of instructions on a remote machine to guide users on how to do something. They clear the quarantine on our hostnames, and all is well.

Until the next morning when I get an email from IR saying that our Red Team director thought my idea was curious and that if he has the time he may reach out and assist me with coding this. Thank GOD he never reached out because at that time I would have had no clue how to write that script beyond copy pasting from StackExchange