Prompt message for logged in user during interactive script

DumbITGuy 96 Reputation points
2021-08-12T12:54:42.21+00:00

I've been tasked with setting up and managing Visual Studio versioning across our Dev PC's.

I've successfully got this up and running, pushing updates to users using Psexec however I would like to add in prompts to advise the users when stages of install are complete or if the setup.exe doesn't run.

I've come to reach the below which of course works fine locally however when running this on a remote users PC the message prompts are not pushed (due to being remote) Is there anyway I could get around this? been trying different psexec commands within the script for the last few days and haven't made much progress :(.

if(get-process setup -ea SilentlyContinue |where-object {-not $.HasExited })
{Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Setup already active - exiting')}
else
{start-process cmd.exe "/c \fileshare\layoutshare\vsupdate.bat"}
start-sleep -s 15
if(get-process setup -ea SilentlyContinue |where-object {-not $
.HasExited })
{$a = get-process setup
$a.waitforexit()
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Installer Update Completed - Advise IT to proceed with next step')
}
else
{Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Install Error - Contact IT')}

It's worth mentioning the vsupdate.bat just contains the one line required to run the silent installer.

The way I'm running this remotely is by running the below on my PC in elevated powershell.
psexec -u adminname -p adminpassword -h -i \devicename cmd.exe /c 'echo . | %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -file "\fileshare\layoutshare\vsinstall.ps1"'

I'm at the point where I've written and tested all of this locally - but I'm getting the same result as I would just running the vsupdate.bat directly from psexec, Ideally i'd love the users to get the prompt so they know when the application is useable again/if there is a problem with the install.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. DumbITGuy 96 Reputation points
    2021-08-18T09:44:52.517+00:00

    So I managed to resolve this by using ps2exe and packing the powershell script into the exe.

    Then using PSexec -u domain\admin -p password -h -i 1 \devicename cmd.exe /c "filepathtoexe"

    This works exactly as I needed - just took some time to get there, thanks!

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,906 Reputation points
    2021-08-12T14:28:08.917+00:00

    Rather than asking PowerShell to do this, why not use "msg.exe" to do it?


  2. Rich Matheisen 45,906 Reputation points
    2021-08-12T18:53:52.51+00:00

    As Perl programmers are wont to say "TMTOWTDI":

    Invoke-Command -ComputerName XXXX -ScriptBlock {
        # the part of the script that does the work goes here
        Invoke-WmiMethod -Class win32_process -Name create -ArgumentList  "c:\windows\system32\msg.exe * XXXX"
    }
    
    0 comments No comments