question

DumbITGuy-6250 avatar image
0 Votes"
DumbITGuy-6250 asked DumbITGuy-6250 answered

Prompt message for logged in user during interactive script

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DumbITGuy-6250 avatar image
0 Votes"
DumbITGuy-6250 answered

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!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered DumbITGuy-6250 commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

II've tried, with adding the command in & also to have the script call a batch file with the msg command, it just doesn't push to the logged in user still.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered DumbITGuy-6250 converted comment to answer

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"
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.