I am looking at creating a powershell module that needs some AD commands from a machines that does not have AD modules installed.
I think that I am misunderstanding the remoting concepts, as I assume it should be straight forward.
I tried to pull down the AD modules and then run the commands
# Create a session to DC
$S = New-PSSession -ComputerName $DC
# Load AD Modules
Invoke-Command -Session $S {Import-Module ActiveDirectory}
# Export the AD cmdlet from remote to local powershell instance
Export-PSSession -Session $S -CommandName *AD* -OutputModule RemAD -AllowClobber -Force
# Remove the session to the DC
Remove-PSSession $S
# Load the local copy of the remote AD modules.
Import-Module RemAD
foreach ($ADG in $ADGroupFilter) {
$Group += Get-ADGroup -Filter {name -like $ADG} | select -ExpandProperty DistinguishedName
$Group
}
The problem that I have is the module complains that the remote computer doesn’t know what is in $ADG
I also tried with Invoke-Command scriptblock {} but seem to have similar issues.
Is there away to pass variables collected from the module parameters to the remote host after you have pulled down the AD modules.
I assume that its a fairly common thing to do but seem to be going around in circles trying to figure it out.
Cheers.