Exe file remote Execution using powershell

I'm trying to write a script which will patch SQL Instances remotely. Referring this forum, I have framed the following line for executing the .exe remotely on other server:

Invoke-Command -ComputerName $computer -ScriptBlock {& cmd /c 'D:\SQL_PATCH\SQLServer2012SP2-KB2958429-x64-ENU.exe'  /qs /action=patch /allinstances /IAcceptSQLServerLicenseTerms}

Open in new window

Also tried this as well:

Invoke-Command -ComputerName $computer -ScriptBlock {& 'D:\SQL_PATCH\SQLServer2012SP2-KB2958429-x64-ENU.exe' -ArgumentList "/qs", "/action=patch", "/allinstances", "/IAcceptSQLServerLicenseTerms"}

Open in new window

Kindly help me on this.
Eldo issacAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Are you getting any errors?  Do you have the access rights to execute those commands on the remote server?
Eldo issacAuthor Commented:
Hello Bob,

There are no errors that I'm getting. But it's not installing everything. Also, on the remote server I have admin rights and powershell remoting has been enabled.
Bob LearnedCommented:
"But it's not installing everything."
We must be clear here:  is it installing anything?  If so, what pieces are missing?

Is there a log file written?

Are all the SQL Servers the same version?
Check Out How Miercom Evaluates Wi-Fi Security!

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom on how WatchGuard's Wi-Fi security stacks up against the competition plus a LIVE demo!

Eldo issacAuthor Commented:
Hello bob,

Apologies for the wrong comment. Actually it's not installing anything. The statement just executes in split second and nothing. There are no log files generated in setup bootstrap and the SQL version is not changing.
Bob LearnedCommented:
It would really help to have a log file here.  It looks like the commands are executable Windows installer files.  If so, then you can enable logging as described here:

How do I create an installation log?
Eldo issacAuthor Commented:
Hello Bob,

The command is for updating SQL to SP2. I looked at the link, didn't understand properly. Can you please suggest an edit in the above command for generating logs?
Run this as a test.  Start a persistent session.
$s =  New-PsSession -computername $computer

Open in new window

Run the remote command using the session.
Invoke-Command -Session $s -ScriptBlock {& D:\SQL_PATCH\SQLServer2012SP2-KB2958429-x64-ENU.exe /qs /action=patch /allinstances /IAcceptSQLServerLicenseTerms}

Open in new window

Check back in a bit to see if the install completed.
Bob LearnedCommented:
I figured out what you are running now:

Installing Updates from the Command Prompt

Unfortunately, i don't see a logging argument in the list of supported arguments, so ignore the man behind the green curtain.
Bob LearnedCommented:
Overview of SQL Server Servicing Installation

By default, SQL Server 2012 update log files are saved to %Program Files%\Microsoft SQL Server\110\Setup Bootstrap\LOG\.
Eldo issacAuthor Commented:
@footech: I tried running your command. No installation is happening but log files are getting generated in setup bootstrap. This is the content of the file:

Exception of type 'System.OutOfMemoryException' was thrown.

The same has been attached here.

@Bob: Still going by the original command, no logs are getting generated at the location u said.
Looking at a link Bob provided, I'd say you need to use the /quiet switch and not /qs.
Eldo issacAuthor Commented:
@footech: Still not the working.
You could try PsExec.  I've encountered things that just won't install (like .Net Framework, think it was a restriction of WUSA.exe) via PS Remoting.  If logging doesn't reveal anything further, I'm out of ideas.
Eldo issacAuthor Commented:
@footech: Can you please tell how can I do that. I have already used PSExec for installing msi on remote servers. Can you please tell how I can I do for exe installation.
This is the command I'm using for msi installation:

    psexec \\$computer -s -u Adminuser -p AdminPassword msiexec /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi /qb ADVANCED_OPTIONS=1 CHANNEL=100

Open in new window

Should be the same as you would use to do a silent install on a local machine.  Maybe
psexec \\computer -s -u Adminuser -p AdminPassword D:\SQL_PATCH\SQLServer2012SP2-KB2958429-x64-ENU.exe /quiet /action=patch /allinstances /IAcceptSQLServerLicenseTerms

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eldo issacAuthor Commented:
Thanks a ton FOOTECH. That just worked fine. Can you please tell one more thing.

Since this script is for updating SQL servers remotely, can you please suggest if I can run the above script parallel on all the servers?
This is required since we have a lot of servers in our environment and we are in the process of automating it. Kindly give your comments in this matter.

Thanks again
To run in parallel you would have to run multiple instances of PsExec.  Think multiple command windows.
Eldo issacAuthor Commented:
No yaar. that wouldn't be possible. We have around 100+ servers. Running multiple instances is not a chance in this scenario.
That's the only way to do it in parallel.  You can provide a list of servers to each instance.  So you could have 5 (or however many) instances running at the same time, and each one would work on a group of servers in a serial fashion.  Limitations of the tool.  Perhaps you could write a batch file (or other script) that would open the command windows and run PsExec in each one.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.