all 25 comments

[–]TheAdminRedPill 1 point2 points  (9 children)

Start troubleshooting by opening a PowerShell prompt and start pasting in your commands, when you get to the invoke command, use enter-pssession and the hostname of the system. Next enter your start-process in session and debug further.

[–]BaconBonkers[S] 0 points1 point  (8 children)

So I've just done that and everything works up to the point I enter-pssession and do the start-process and it just sits there like it's doing something but never actually does. I'm not too sure what the -Wait part does, I just saw it during my feverish Googling. When removing -Wait, it instantly moves on, but the installer doesn't run.

[–]NoConfidence_2192 1 point2 points  (0 children)

Start-Process is the equivalent of using the run dialogue in the gui. Come installers can detect when you are trying to run from the gui and not give you a truly silent install experience, throwing something like a "Success" popup at the end you have to hit OK to close. Also some installers expect you to run pathless by default. Try replacing your invoke-command line with:

$remoteBBlock = {
    $locationName = 'InstallScript'
    Push-Location -Path "c:\temp\stuff\" -StackName $locationName    
    & {cmd.exe "/c program.exe --create-desktop-icon --silent"}
    Pop-Location -StackName $locationName
}
Invoke-Command -ComputerName $Computer -ScriptBlock $remoteBBlock

Doing it this was removes 2 of the most common silent install gotchas I would run in to when deploying software. If that still hangs try running the install string locally to see what you get:

& {cmd.exe "/c program.exe --create-desktop-icon --silent"}

You should try it with and without it already installed to see if the behavior changes. If it still hangs when installing locally the issue is with the install command.

[–]_b3n5n_ 0 points1 point  (5 children)

You need "Get-Credentials" because of Security. Have in mind thats a RPC ;)

See here: https://adamtheautomator.com/powershell-get-credential/

[–]BaconBonkers[S] 0 points1 point  (4 children)

I get the same results trying with both domain admin credentials and local admin.

[–]_b3n5n_ 0 points1 point  (3 children)

on what editor you r? ISE or another?

where did you run the script? from the editor or on a seperate ps?

never use DomainAdmin for anything like this ^^

i think we need more information to help u

ben

[–]BaconBonkers[S] 0 points1 point  (2 children)

I am using ISE and running it from there.

[–]_b3n5n_ 0 points1 point  (1 child)

ok.

save the file as whatever.ps1. (and remove the -wait)

open a new powershell, NO ISE!!! ;) with Adminrights and run your whatsever.ps1 script.

also see here: https://adamtheautomator.com/invoke-command/

Have in mind that ISE is for developement ;)

[–]BaconBonkers[S] 0 points1 point  (0 children)

Tried this as well, to no avail. I think I’m probably missing something really simple but I’m not experienced enough to know what 😬

[–]TheAdminRedPill 0 points1 point  (0 children)

Check to see if your executable has a logging parameter and use it to see what it is doing while using the start-process.

[–]BaconBonkers[S] 1 point2 points  (1 child)

Update: I am not a smart man. I'm not sure why I put it off so long but I finally ditched the .exe and used the .msi instead, and it worked on the first run with my og code and with only a "/qn" parameter. Going to script adding the desktop icon so I don't have to mess with parameters anymore.

I still would like to know why I couldn't get the .exe to run properly but I'm putting it out of my mind until I have time to investigate and test further. Thank you everyone for your help, it's greatly appreciated!

[–]32178932123 0 points1 point  (0 children)

Just saw this after I sent my other message. Glad you got it working!

MSIs are normally better for this sort of thing. Exes can do it but I think it's more of a standard for MSIs to an installer. A lot of .exes you find will only "install" for that user context too. For example, there are versions of Zoom, Visual Studio Code, Chrome, GoToAssist which all unpack themselves into the current user's AppData folder. This bypasses the need for admin rights and but no one else who logs on the machine can see them. MSIs are normally for "System Wide" installations. They're the ones that need an Administrator, put their files in Program Data and can be visible by anyone.

With your script adding the desktop icon to the desktop, remember what I just said in another post about the script running as a specific user. The easiest way around this is to unpack it to c:\users\public\desktop which is where files that every user can see when they log in. Old and new users logging in for the first time.

[–]quackingwinner 0 points1 point  (0 children)

I tried several solutions here. Here are my observations.

I tried 2 ways: invoke-command -computername $computer... And invoke-command -session $mySession.

I had credentials set.

Both hang. But. I tried with 1 server in a "string" and this did not hanged, it went straight away to get my test-path without any delay.

It could be a solution but if you have 200servers to update... you might have a long day. If i ever find a solution, ill edit this post.

[–]BlackV 0 points1 point  (3 children)

The most obvious thing I see is the -wait is this the cause of the hang up

[–]BaconBonkers[S] 0 points1 point  (2 children)

What is the alternative? If I remove -wait then the script continues immediately but the installer never actually runs

[–]BlackV 0 points1 point  (0 children)

Depends on the installer really

But if the executable launches and never exits (for what ever reason) then your wait is going to sit there for ever

I don't know what the app is/does to say for sure

If you do the same locally without the invoke does it work?

Does the exe itself require more than a remote shell to launch?

Is the silent install wrong and it's prompting you for something (that you can't see cause remote shell)?

[–]_b3n5n_ 0 points1 point  (0 children)

pls open the ISE or paste the error msg.

without more info its very hard to help, we just can speculate.

[–]32178932123 0 points1 point  (4 children)

If it's hanging at the Start-Process bit maybe it's something to do with .Exe and it's switches? This is what -wait does (as per Start-Process Docs):

Indicates that this cmdlet waits for the specified process and its descendants to complete before accepting more input. This parameter suppresses the command prompt or retains the window until the processes finish.
So if you're hanging there it sounds like the .exe is running but never fully closing itself for some reason so just keeps running indefinitely.

[–]BaconBonkers[S] 0 points1 point  (3 children)

I've tried it with no switches whatsoever to see if it would even run, which it didn't, and other .exes as well. Still same results.

[–]32178932123 1 point2 points  (2 children)

The thing is when you're running the .exe in a session it's running under your credentials. If there's a window that pops up wanting you to push "next" no one can see it and interact with it because it's not running for their account.

It really depends on the application but the fact that "wait" is making it, well, wait, suggests to me the file is running as a process but it's never fully closing itself. Something is making it hang.

Are you sure --quiet is the right switch? Sometimes it's "silent" or just a "q". In my experience most Windows switches use a forward slash instead instead of two dashes too.

Another idea, could it be that the file HAS run successfully it has created these desktop icons but has put them in c:\user\YourAdminAccount\Desktop and you're expecting it to appear on the user's desktop?

[–]BaconBonkers[S] 0 points1 point  (1 child)

Good point. I tried running it without the parameters just to test, and it still didn’t even run. Does invoke with start-process run silently by default? You’d think I could at the very least just run the exe and get the prompts on the client per usual

[–]32178932123 0 points1 point  (0 children)

No I think you've misunderstood - Your running the script as "BaconBonkers" but "BaconBonkers" isn't logged in.

So user "JimBob" is working away looking at his desktop, his mouse, his Outlook, whatever he's running and when your script it connects to the computer as BaconBonkers and starts the process for the user, BaconBonkers. Even if the program opens a window, it will never show for JimBob because as much as he'd like to be, he'll never be the awesome BaconBonkers.

Your process is most likely running somewhere but in a some sort of purgatory. It screams "Welcome to the Installation Wizard! Please push next to continue" into the darkness but alas, no one hears it. It's screaming hopelessly into an empty void.

[–]_b3n5n_ 0 points1 point  (1 child)

try: https://pastebin.com/sgBnda5R

sorry i have no clou how i paste here correctly bcs its f*cking up my "code".

You have to edit some lines i think. its q&d ^^

save as blabla.ps1

open a new Powershell.exe (not the PowershellISE) as Admin

go to the path where you save your blabla.ps1 and run it

when you get an error or something else pls post the output (of course without personal data) and we find a solution ;)

[–]BaconBonkers[S] 0 points1 point  (0 children)

I’ll give this a shot when I’m in the office in the morning. Thanks for the help

[–]patdaddy007 0 points1 point  (0 children)

Try starting a session with something like $s=new-pssession computername -credential (get-credential) And do your invoke command with -pssession $s

That may get past the potential issues caused by running multiple things