So I am writing a script to run on users machine that do not have AD or quest modules for AD lookup.
The clients are Windows 7 so I have Powershell 2.0 on the domain PC's which I cannot upgrade.
From the clients PC I will be running a command to connect to a server as particular user with elevated rights
So it will be as follows
Invoke-command -cred $cred -ComputerName $Server -scriptblock { Get-aduser $Domain_User -Properties Extensionattribute1, ExtensionAttribute2}
I need to keep the values in the extensionAttributes for later use
Is this achievable ?
Return data from remote PC connection
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Return data from remote PC connection
You are trying to use the AD cmdlets against machines that don't have the AD module?
- bsmith1965
- Posts: 5
- Last visit: Tue Sep 14, 2021 7:22 am
Re: Return data from remote PC connection
To make this simpler I need to get 2 extension attributes , I have to have 1 returned in a variable and the other in another variable.
The PC's where this script will eventually run has PS 2.0 and nothing else so I need to remote a server and get the attributes here, Here is my script
$Gloabal:samid = $env:USERNAME # Get SamAccountName
$UAdmin = 'Service@domain.net # Service account with necessary rights
$Password = Get-Content C:\Support\UP.txt | convertto-securestring # Get previously save password
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $UAdmin, $Password # Crete credential Object
$Server = "Server.domain.net" # FQDN of the Server with AD CMDlets
$ext1 = Invoke-Command -credential $Credential -ComputerName $Server -ScriptBlock { Get-ADUser $samid -Properties ExtensionAttribute1 } # Get ext1
$ext2 = Invoke-Command -credential $Credential -ComputerName $Server -ScriptBlock { Get-ADUser $samid -Properties ExtensionAttribute2 } # Get ext2
I plan to set these ext1 and 2 properties later once I do some validation.
The PC's where this script will eventually run has PS 2.0 and nothing else so I need to remote a server and get the attributes here, Here is my script
$Gloabal:samid = $env:USERNAME # Get SamAccountName
$UAdmin = 'Service@domain.net # Service account with necessary rights
$Password = Get-Content C:\Support\UP.txt | convertto-securestring # Get previously save password
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $UAdmin, $Password # Crete credential Object
$Server = "Server.domain.net" # FQDN of the Server with AD CMDlets
$ext1 = Invoke-Command -credential $Credential -ComputerName $Server -ScriptBlock { Get-ADUser $samid -Properties ExtensionAttribute1 } # Get ext1
$ext2 = Invoke-Command -credential $Credential -ComputerName $Server -ScriptBlock { Get-ADUser $samid -Properties ExtensionAttribute2 } # Get ext2
I plan to set these ext1 and 2 properties later once I do some validation.
Re: Return data from remote PC connection
Here is how we would do this in PowerShell:
- # never save passwords in a text file. You might as well post the password on Twitter
- $Credential = Get-Credential Service@domain.net
- $sb = { Get-ADUser $args[0] -Properties ExtensionAttribute1, ExtensionAttribute2 }
- $user = Invoke-Command -ScriptBlock $sb -credential $Credential -ComputerName 'Server.domain.net' -ArgumentList $env:USERNAME
- $user.ExtensionAttribute1
- $user.ExtensionAttribute2