Needing Help Creating a .bat file with Powershell Incorporated

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xxmlckyxx
Posts: 3
Joined: 14 Apr 2016 10:09

Needing Help Creating a .bat file with Powershell Incorporated

#1 Post by xxmlckyxx » 14 Apr 2016 11:40

I am trying to make a .bat file I am trying to run powershell in it so I can run psexec to open cmd.exe in a another computer to do a gpupdate /force. I am trying to have them prompt to enter the computer number and then psexec would run with that computer number

I have the following so far but its not working. I am needing help...

echo Please Run As Your Admin Account
cls
pause

Powershell
echo please type in computer name
echo %computername%
pause
powershell -command "C:\utilities\pstools\psexec.exe" \\%computername&\ cmd.exe
gpupdate /force
exit



Thanks

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Needing Help Creating a .bat file with Powershell Incorporated

#2 Post by Squashman » 14 Apr 2016 12:08

Why do you think you need to use Powershell to do this. You can just run PSEXEC by itself.

Your gpupdate command will only run on the local computer. If want it to run on a remote computer then you will need to use PSEXEC for that as well.

xxmlckyxx
Posts: 3
Joined: 14 Apr 2016 10:09

Re: Needing Help Creating a .bat file with Powershell Incorporated

#3 Post by xxmlckyxx » 14 Apr 2016 15:21

I assumed I needed power shell for that. so when I run the psexec command.exe it opens a new window but the computer number doesnt populate. Do you know what the code would be or what I need to write to fix it?

xxmlckyxx
Posts: 3
Joined: 14 Apr 2016 10:09

Re: Needing Help Creating a .bat file with Powershell Incorporated

#4 Post by xxmlckyxx » 14 Apr 2016 15:25

So how would I make the script to run psec to do a gpupdate? I want it to have them enter the computer number and with that the cmd.exe will open to that specific computer number and run the gpupdate

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Needing Help Creating a .bat file with Powershell Incorporated

#5 Post by Squashman » 15 Apr 2016 11:35

You should probably take a step back and learn to use the commands first before trying to put them into a batch file.
Can you get PSEXEC to work by manually running it from the cmd prompt?
Your PSEXEC code example does not use any user name or password. Usually when you are trying to connect to a remote computer that is going to require credentials. If the user name and password of the computer you are using is not the same on the remote computer then you need to provide the username and password with PSEXEC.

Code: Select all

psexec \\remotepc -u Squashman -p Password gpudate

Post Reply