running command with admin privilages on remote machine win7

by rmishra at 2013-04-05 03:11:46

I need to execute my exe file present in my remote machine (like running - run as administrator ) . So far i have tried start-process cmd.exe -Verb runas -argumentlists “path of EXE” but this is failing.

Let me explains you my actual requirements - I have Win7 server A - where my all exe files are present. I need to run each exe as Run as Administrator, once the exe started running then wait for 2 min. reboot the server and start running another exe.
So I have thought of creating PowerShell script which i will execute from my workstation.
by MasterOfTheHat at 2013-04-05 08:49:11
Have you tried something like this?
$securePassword = ConvertTo-SecureString -string “password” -AsPlainText -Force
$user = New-Object Management.Automation.PSCredential(“username”, @securePassword)
Invoke-Command -computername server01 -scriptBlock {c:\testapp.exe} -Credential $user

(Credit to Mattias Samskar’s blog)

Or even just like:
Invoke-Command -computername server01 -scriptBlock {c:\testapp.exe} -Credential (Get-Credential)
You could include the syntax to wait for a while and then reboot in the scriptBlock parameter.
by rmishra at 2013-04-05 13:32:45
Thanks MasterOfTheHat,

But I can’t use invoke-command, as my server is in public domain, so enable psremoting is throwing error that network connection should be in domain or private network.

As my server is a VSphere VM so I am using powerCLI to connect from workstation to VM and then using invoke-VMScript cmdlet for invoking commands.