I cannot get a remote session working properly.
If I use the following code:
$cred = Get-Credential
$session = New-PSSession -ComputerName DC1 -Credential $cred
Invoke-Command $session -Scriptblock { Import-Module ActiveDirectory }
Import-PSSession -Session $session -Module ActiveDirectory #-Prefix Rem
$user = Get-ADUser ???? -Properties *
The get-aduser cmdlet does not work.
However, if I don't try to import the session :
$cred = Get-Credential
$session = New-PSSession -ComputerName DC1 -Credential $cred
$user = Invoke-Command -Session $session { Get-ADUser ???? -Properties * }
This works fine and the user is retrieved.
Must be doing something fundamentally wrong, however, I just can't spot it.
Any help most appreciated.
Thanks
Ian
Remote Powershell Session oddity
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.
Re: Remote Powershell Session oddity
I thought it just imported the reference to the cmdlets, a bit like having RSAT.
Certainly there are many blogs etc out there referencing the ability to Import the active directory module into the current session.
Rather confusing. However, as I now have working, I will continue to use the Invoke Command using the current session.
Regards
Ian
Certainly there are many blogs etc out there referencing the ability to Import the active directory module into the current session.
Rather confusing. However, as I now have working, I will continue to use the Invoke Command using the current session.
Regards
Ian
Re: Remote Powershell Session oddity
I thought that was what I was doing. Creating a new session to my DC and importing the AD commands into the local session.
Indeed, if I run the commands above in a powershell windows on a PC that doesn't have RSAT, the commands produce the desired effect and I can run the get-aduser cmdlet as expected. However, the same code in a ps studio form does not unless I use the second block of code.
As such I'm assuming the issue lies somewhere in the forms structure.
Regards
Ian
Indeed, if I run the commands above in a powershell windows on a PC that doesn't have RSAT, the commands produce the desired effect and I can run the get-aduser cmdlet as expected. However, the same code in a ps studio form does not unless I use the second block of code.
As such I'm assuming the issue lies somewhere in the forms structure.
Regards
Ian