Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Powershell Execute process

Closed Thread
 
Thread Tools Display Modes
Old 04-16-2008   #1 (permalink)
Amit Tank
Guest


 

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?
Old 04-16-2008   #2 (permalink)
RichS [MVP]
Guest


 

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?
>
Old 04-16-2008   #3 (permalink)
Amit Tank
Guest


 

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 -
Old 04-16-2008   #4 (permalink)
Amit Tank
Guest


 

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 -
Old 04-16-2008   #5 (permalink)
Marco Shaw [MVP]
Guest


 

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
Old 04-16-2008   #6 (permalink)
Amit Tank
Guest


 

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 -
Old 04-16-2008   #7 (permalink)
Marco Shaw [MVP]
Guest


 

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
Old 04-16-2008   #8 (permalink)
Amit Tank
Guest


 

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
Old 04-16-2008   #9 (permalink)
Marco Shaw [MVP]
Guest


 

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
Old 04-16-2008   #10 (permalink)
Amit Tank
Guest


 

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: