Running a powershell script from batch file as DIFFERENT USER (non interactively)

Hi Friends,
 I need your valuable suggestion on how I can achieve the following:

OS: Windows

In short: I want to understand how can I RUN a Powershell script from a Batch file by providing domain credentials (NON-INTERACTIVELY).

Here is my scenario in detail:

I have a java program, started by a Service, which creates a batch file on the fly which will have to invoke a powershell script during runtime and the powershell script has some cmdlets which need to RUN as DOMAIN USER, otherwise those cmdlets wont return values. Currently I am using a work around like.. I am running the service as the domain user and able to get the data from cmdlets, but when I run the service as Local System account I am not getting data from cmdlet.

Can you please suggest a better way to accomplish what i wanted.. getting data from cmdlet without having to run the service as domain user. Can I run the powershell script as DOMAIN USER from within the batch file. The program which creates the batch file has domain user credentials (username & password).

Please note that WinRM is disabled in the environment, otherwise I could use Invoke-Command with details and make things work without having to run the service as domain user.

Thanks a lot for your valuable suggestions.

Regards,
LVL 2
Krishna VAsked:
Who is Participating?

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

x
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.

Kyle AbrahamsSenior .Net DeveloperCommented:
From:
http://community.spiceworks.com/topic/368007-runas-batch-including-password

You can use psExec as an option or you could use PowerShell remoting.

Powershell
$user = "username"
$pass = "password" | convertto-securestring -asplaintext -force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass


<#this is a list of computers, but you can use just your local machine #>
$list = get-content C:\list.txt 

foreach($item in $list){
$session = new-pssession $item -Credential $cred
invoke-command -Session $session {desired thing here}
}

Open in new window

0
footechCommented:
Non-interactively is a problem.
In my opinion, running the service as a domain user is the way this should be done.

One other possibility I see is to create a scheduled task that runs with the credentials you want.  Then just have the batch file run the scheduled task via the schtasks.exe command on demand.
0

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
Krishna VAuthor Commented:
Thanks Kyle and footech for your suggestions. But my question is still un-answered as I cannot use powershell remoting.
0
Kyle AbrahamsSenior .Net DeveloperCommented:
what about ps exec?
0
footechCommented:
Neither of my suggestions mentioned PS Remoting.
0
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
Powershell

From novice to tech pro — start learning today.