Prompt message for logged in user during interactive script

DumbITGuy 96 Reputation points

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')}
{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
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Installer Update Completed - Advise IT to proceed with next step')
{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,411 questions
0 comments No comments
{count} votes

Accepted answer
  1. DumbITGuy 96 Reputation points

    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,111 Reputation points

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

  2. Rich Matheisen 45,111 Reputation points

    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