View Single Post
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