SqlHog
SqlHog

Reputation: 31

Powershell Remote Computer Session

I can run the following command from my desktop out of my HQ domain but I am unable to create a Remote Powershell session. I have searched many posts and can not determine how to resolve this.

$TargetServer = 'RemoteComputer'
Get-WmiObject -Namespace "root\cimv2" -Class Win32_Process -Impersonation 3 -Credential RemoteDomain\username -ComputerName $TargetServer 

Need this to work, please note that if i am logged into a management server in the remote domain the command works with my default nt permissions.:

$TargetServerSession = New-PSSession -Credential RemoteDomain\username -ComputerName $TargetServer

Upvotes: 0

Views: 201

Answers (1)

30000MONKEYS
30000MONKEYS

Reputation: 195

What's the Error you are getting? Maybe it's a credential thing, I kind of miss the get-credential part.

YourUser needs local Admin rights on the remote machine and you need to provide a password for the session.

You enter a PSSession by doing this:

# * Define name of remote machine
$TargetServer = "RemoteComputer"

# * Get a password prompt for the user 'YourUser' and store the creds
$Cred = (Get-Credential YourDomain\YourUser)

# * Create a PSSession for the Remote Computer using the Credentials you just provided
$PSSession = new-pssession -Computer $TargetServer -Credential $Cred

# * Enter the session
Enter-PSSession $PSSession

If this code is not working, then we need more infos.

Upvotes: 1

Related Questions