I need to connect to a server that is in another domain. From that server I connect to 3 other domains to look up user accounts in each of those domains.
I connect to the terminal server, and then run 'invoke-command'. A few problems occur:
1st - I specify what my credentials are, yet when i run the script it prompts for credentials.
2nd - i get an error stating that the invokemethod is null
Here's the script:
PARAM (
[Parameter(ValueFromPipeline)]
$FullName
)
###Creds###
$Password = Read-Host -AsSecureString "Enter Your Password"
$apcred = New-Object System.Management.Automation.PSCredential
("server\username",$Password)
### Double Hop ###
$Session = New-PSSession -Name RDP -ComputerName Server.com -Credential
($apcred)
Enable-WSManCredSSP -Role Client -DelegateComputer server.com -Force
Invoke-Command -Session $session -ScriptBlock {Enable-WSManCredSSP -Role
Server -Force}
Invoke-Command -Session $session -ScriptBlock {
$rrs = Get-ADUser -Filter * -Server server2.com -Credential ($apcred)
$rrsusers = ($rrs | Where-Object{$_.name -eq $Name})
This is the error I get:
You cannot call a method on a null-valued expression.
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull