Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Powershell Execute process

Reply
 
Old 04-16-2008   #1 (permalink)
Amit Tank


 
 

Powershell Execute process

I want to execute a command at remote DMZ server with below line. But
it is not authenticating the password and giving access denied error
even though password is correct & able to access remote share with
same password.

$ProcessClass = get-wmiobject -query "SELECT * FROM Meta_Class WHERE
__Class = 'Win32_Process'" -namespace "root\cimv2" -credential $(Get-
Credential) -computername $computer
$results = $ProcessClass.Create( $commandline )

::::::::::Error :::::::::
Exception retrieving member "Create": "Access is denied. (Exception
from HRESUL
T: 0x80070005 (E_ACCESSDENIED))"
At C:\ExeCmd.ps1:72 char:11
+ $results = <<<< $ProcessClass.Create($commandline)

Any idea how to pass the credential safely?

My System SpecsSystem Spec
Old 04-16-2008   #2 (permalink)
RichS [MVP]


 
 

RE: Powershell Execute process

This has come up before if I remember correctly. You need to do the
get-credential as a seperate prior step

$cred = get-credential
get-wmiobject ........... -credentials $cred ..........


--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Amit Tank" wrote:
Quote:

> I want to execute a command at remote DMZ server with below line. But
> it is not authenticating the password and giving access denied error
> even though password is correct & able to access remote share with
> same password.
>
> $ProcessClass = get-wmiobject -query "SELECT * FROM Meta_Class WHERE
> __Class = 'Win32_Process'" -namespace "root\cimv2" -credential $(Get-
> Credential) -computername $computer
> $results = $ProcessClass.Create( $commandline )
>
> ::::::::::Error :::::::::
> Exception retrieving member "Create": "Access is denied. (Exception
> from HRESUL
> T: 0x80070005 (E_ACCESSDENIED))"
> At C:\ExeCmd.ps1:72 char:11
> + $results = <<<< $ProcessClass.Create($commandline)
>
> Any idea how to pass the credential safely?
>
My System SpecsSystem Spec
Old 04-16-2008   #3 (permalink)
Amit Tank


 
 

Re: Powershell Execute process

I tried that and checked again but same error.

It takes credential correctly when we give below
$ProcessClass = get-wmiobject -class "Win32_Process" -namespace "root
\cimv2" -credential $(Get-Credential) -computername $computer

But this code doesn't allow to run create( ) method to execute command
at remote machine like below.
$results = $ProcessClass.Create( $commandline )


On Apr 16, 3:37*am, RichS [MVP] <RichS...@xxxxxx>
wrote:
Quote:

> This has come up before if I remember correctly. *You need to do the
> get-credential as a seperate prior step
>
> $cred = get-credential
> get-wmiobject ........... *-credentials $cred ..........
>
> --
> Richard Siddaway
> All scripts are supplied "as is" and with no warranty
> PowerShell MVP
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
>
>
> "Amit Tank" wrote:
Quote:

> > I want to execute a command at remote DMZ server with below line. But
> > it is not authenticating the password and giving access denied error
> > even though password is correct & able to access remote share with
> > same password.
>
Quote:

> > * $ProcessClass = get-wmiobject -query "SELECT * FROM Meta_Class WHERE
> > *__Class = 'Win32_Process'" -namespace "root\cimv2" -credential $(Get-
> > Credential) -computername $computer
> > * * $results = $ProcessClass.Create( $commandline )
>
Quote:

> > ::::::::::Error :::::::::
> > Exception retrieving member "Create": "Access is denied. (Exception
> > from HRESUL
> > T: 0x80070005 (E_ACCESSDENIED))"
> > At C:\ExeCmd.ps1:72 char:11
> > + $results = *<<<< $ProcessClass.Create($commandline)
>
Quote:

> > Any idea how to pass the credential safely?- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec
Old 04-16-2008   #4 (permalink)
Amit Tank


 
 

Re: Powershell Execute process

I tried other two methods also and let me explain in detail.

I want to execute a process on a server which is in DMZ & workgroup
from my domain.

It works if,
- If I keep the same password of my domain ID and user ID of that
server then it works.
- I can access the \\ServerName\C$ with my user ID of DMZ server from
domain.
- If I run these scripts against a server which is in same domain then
it works.

It doesn't work
- If passwords are different for my domain ID and user ID of remote
DMZ server and if I pass the password through PowerShell.

## 1 ##
$co = new-object management.connectionoptions
$co.Username = "ServerName\UserID"
$co.SecurePassword = (read-host -assecurestring)
$scope = new-object management.managementscope "\\ServerName\root
\cimv2",$co
$scope.Connect()
$mp = new-object management.managementpath "win32_process"
$ogo = new-object management.objectgetoptions
$proc = new-object management.managementclass $scope,$mp,$ogo
$proc.Create("notepad.exe")

## 2 ##
$comp = "ServerName"
$cre = get-credential ServerName\UserID
$win32ProcessClass = Get-WmiObject -List -Namespace 'root\cimv2' -
credential $cre -computername $comp | Where-Object { $_.Name -eq
'Win32_Process' }
$win32ProcessClass.Create("notepad.exe")

Any help is really appreciated.

Amit

On Apr 16, 3:51*am, Amit Tank <amitmt...@xxxxxx> wrote:
Quote:

> I tried that and checked again but same error.
>
> It takes credential correctly when we give below
> $ProcessClass = get-wmiobject -class "Win32_Process" -namespace "root
> \cimv2" -credential $(Get-Credential) -computername $computer
>
> But this code doesn't allow to run create( ) method to execute command
> at remote machine like below.
> * $results = $ProcessClass.Create( $commandline )
>
> On Apr 16, 3:37*am, RichS [MVP] <RichS...@xxxxxx>
> wrote:
>
>
>
Quote:

> > This has come up before if I remember correctly. *You need to do the
> > get-credential as a seperate prior step
>
Quote:

> > $cred = get-credential
> > get-wmiobject ........... *-credentials $cred ..........
>
Quote:

> > --
> > Richard Siddaway
> > All scripts are supplied "as is" and with no warranty
> > PowerShell MVP
> > Blog:http://richardsiddaway.spaces.live.com/
> > PowerShell User Group:http://www.get-psuguk.org.uk
>
Quote:

> > "Amit Tank" wrote:
Quote:

> > > I want to execute a command at remote DMZ server with below line. But
> > > it is not authenticating the password and giving access denied error
> > > even though password is correct & able to access remote share with
> > > same password.
>
Quote:
Quote:

> > > * $ProcessClass = get-wmiobject -query "SELECT * FROM Meta_Class WHERE
> > > *__Class = 'Win32_Process'" -namespace "root\cimv2" -credential $(Get-
> > > Credential) -computername $computer
> > > * * $results = $ProcessClass.Create( $commandline )
>
Quote:
Quote:

> > > ::::::::::Error :::::::::
> > > Exception retrieving member "Create": "Access is denied. (Exception
> > > from HRESUL
> > > T: 0x80070005 (E_ACCESSDENIED))"
> > > At C:\ExeCmd.ps1:72 char:11
> > > + $results = *<<<< $ProcessClass.Create($commandline)
>
Quote:
Quote:

> > > Any idea how to pass the credential safely?- Hide quoted text -
>
Quote:

> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec
Old 04-16-2008   #5 (permalink)
Marco Shaw [MVP]


 
 

Re: Powershell Execute process

I'm sorry, what are you identifying here:
Quote:

> ## 1 ##
> $co = new-object management.connectionoptions
> $co.Username = "ServerName\UserID"
> $co.SecurePassword = (read-host -assecurestring)
> $scope = new-object management.managementscope "\\ServerName\root
> \cimv2",$co
> $scope.Connect()
> $mp = new-object management.managementpath "win32_process"
> $ogo = new-object management.objectgetoptions
> $proc = new-object management.managementclass $scope,$mp,$ogo
> $proc.Create("notepad.exe")
>
> ## 2 ##
> $comp = "ServerName"
> $cre = get-credential ServerName\UserID
> $win32ProcessClass = Get-WmiObject -List -Namespace 'root\cimv2' -
> credential $cre -computername $comp | Where-Object { $_.Name -eq
> 'Win32_Process' }
> $win32ProcessClass.Create("notepad.exe")
Neither works in your last scenario?

I understand there are some small cross-domain authentation issues with
get-wmiobject in v1.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 04-16-2008   #6 (permalink)
Amit Tank


 
 

Re: Powershell Execute process

Thanks for the information Macro.

Is it corrected in v2? if you come across. Or any alternate way to
execute process.

On Apr 16, 4:40*pm, "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com>
wrote:
Quote:

> I'm sorry, what are you identifying here:
>
>
>
>
>
Quote:

> > ## 1 ##
> > $co = new-object management.connectionoptions
> > $co.Username = "ServerName\UserID"
> > $co.SecurePassword = (read-host -assecurestring)
> > $scope = new-object management.managementscope "\\ServerName\root
> > \cimv2",$co
> > $scope.Connect()
> > $mp = new-object management.managementpath "win32_process"
> > $ogo = new-object management.objectgetoptions
> > $proc = new-object management.managementclass $scope,$mp,$ogo
> > $proc.Create("notepad.exe")
>
Quote:

> > ## 2 ##
> > $comp = "ServerName"
> > $cre = get-credential ServerName\UserID
> > $win32ProcessClass = Get-WmiObject -List -Namespace 'root\cimv2' -
> > credential $cre -computername $comp | Where-Object { $_.Name -eq
> > 'Win32_Process' }
> > $win32ProcessClass.Create("notepad.exe")
>
> Neither works in your last scenario?
>
> I understand there are some small cross-domain authentation issues with
> get-wmiobject in v1.
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShellhttp://www.microsoft.com/mvp
>
> PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
> Blog:http://marcoshaw.blogspot.com- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec
Old 04-16-2008   #7 (permalink)
Marco Shaw [MVP]


 
 

Re: Powershell Execute process

Amit Tank wrote:
Quote:

> Thanks for the information Macro.
>
> Is it corrected in v2? if you come across. Or any alternate way to
> execute process.
There are some WMI related fixes in the current v2 CTP (for
non-production use and available now).

You can also use winrm to execute remote commands.

I'm not sure how far you are willing to go to try to make this work.

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 04-16-2008   #8 (permalink)
Amit Tank


 
 

Re: Powershell Execute process

I think winrm configuration is not advisable for Edge server because
it directly contact to internet. Am I right ?

On Apr 16, 7:27*pm, "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com>
wrote:
Quote:

> Amit Tank wrote:
Quote:

> > Thanks for the information Macro.
>
Quote:

> > Is it corrected in v2? if you come across. Or any alternate way to
> > execute process.
>
> There are some WMI related fixes in the current v2 CTP (for
> non-production use and available now).
>
> You can also use winrm to execute remote commands.
>
> I'm not sure how far you are willing to go to try to make this work.
>
> --
> Microsoft MVP - Windows PowerShellhttp://www.microsoft.com/mvp
>
> PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
> Blog:http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 04-16-2008   #9 (permalink)
Marco Shaw [MVP]


 
 

Re: Powershell Execute process

Amit Tank wrote:
Quote:

> I think winrm configuration is not advisable for Edge server because
> it directly contact to internet. Am I right ?
By default, winrm will listen on all available addresses, but you can
edit that list.

Furthermore, you can use the Windows Firewall client in certain conditions.

Marco
My System SpecsSystem Spec
Old 04-16-2008   #10 (permalink)
Amit Tank


 
 

Re: Powershell Execute process


Thanks for your advice Marco, really appreciate.

On Apr 16, 7:58*pm, "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com>
wrote:
Quote:

> Amit Tank wrote:
Quote:

> > I think winrm configuration is not advisable for Edge server because
> > it directly contact to internet. Am I right ?
>
> By default, winrm will listen on all available addresses, but you can
> edit that list.
>
> Furthermore, you can use the Windows Firewall client in certain conditions..
>
> Marco
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to execute external program from powershell PowerShell
Can only execute gpg from powershell under MY account PowerShell
Execute a powershell script from a webpage PowerShell
How to execute a webtest from Powershell PowerShell
How to execute (perl) scripts in Powershell without DOS box PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46