Solved

Help executing a batch file on a remote PC using Powershell (PSRemote)

Posted on 2013-12-30
2
6,684 Views
Last Modified: 2014-01-12
Good Morning Powershell Experts,

I have been asked to uninstall all old versions of Adobe Flash and install the newest version on several hundred PCs.  I’ve read about doing this with a GPO or through SCCM (we use SCCM 2007), but I have not been successful with either of these options.  The cleanest way I have found to do this is using the following script (named AdobeFlashInstall.cmd):

taskkill /f /t /im iexplore.exe
pushd "\\netapp3140a\sccmdata$\sources\apps\AdobeFlashPlayer"
Uninstall_flash_player.exe -uninstall -force
Install_flash_player_11_active_x.msi /QB!
Popd

What I would like to do is use Powershell to launch the AdobeFlashInstall.cmd script on the remote PCs.  

To see how well this would work, I’m trying to initiate a remote launch of the AdobeFlashInstall.cmd script on one of my test machines.  The Powershell command I’m using is as follows:

Invoke-command –ComputerName TestPC1 –ScriptBlock {Start-Process “\\Server1\SharedApps\Adobe\InstallAdobeFlash.cmd”} –credential mydomain\nick

When I run the command above, I’m prompted for my password, which I enter, and then I get the following error:

This command cannot be executed due to the error:  Access is denied.
      + CategoryInfo            : InvalidOperation: (:) [Start-Process], InvalidOperationException
      + FullyQualifiedErrorID : InvalidOperationException,Microsoft.Powershell.Commands.StartProcessCommand
      + PSComputerName      : TestPC1

I have verified PSRemoting is enabled and working on the test machine using the following command:

Invoke-command – ComputerName TestPC1 –ScriptBlock {Get-Process} –credential mydomain\nickd

The above command works.

I have verified that everyone has access to the share on the server.  I have also added domain computers to have access on the share.  I have tested this by accessing the share from my PC and one of my other test PCs without any issues.  Any ideas on what I’m doing wrong?

As always, thanks in advance for your help.

Nick
0
Comment
Question by:ndalmolin_13
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39746388
When accessing remote shares from within a remote PS session, you will need to use credssp.  Basically the reason you're getting access denied is because when it tries to access "\\Server1\SharedApps\Adobe\InstallAdobeFlash.cmd" from within the remote session it doesn't have any credentials.  The following links do a good job of explaining the situation and how to configure PS to use CredSSP so that credentials are passed on.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell-quot-second-hop-quot-functionality-with-credssp.aspx
http://dustinhatch.tumblr.com/post/24589312635/enable-powershell-remoting-with-credssp-using-group

After that is set up you would need to modify your invoke-command to be more like
Invoke-command –ComputerName TestPC1 –ScriptBlock {Start-Process "\\Server1\SharedApps\Adobe\InstallAdobeFlash.cmd"} –credential mydomain\nick -authentication credssp

Open in new window

However, I'm not 100% certain that calling start-process with the .CMD script will do what you want it to, but you'll find out!
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39746579
Alternate way is to try with PsExec to execute the batch file..
http://ss64.com/nt/psexec.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
This article will help you understand what HashTables are and how to use them in PowerShell.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now