Hello,
I'm trying to open Implicit Remoting session to import certain modules from the remote server. I'm able to import required modules and close the session normally.
But I'm unable to check whether the required module is already loaded or not before opening the Implicit Remoting session. The following code works under normal circumstances, but not with Implicit Remoting...
Any further help would be greatly appreciated. Thank you!
By loading module locally
By loading module via Implicit Remoting sessionif(!(Get-Module -name "ActiveDirectory")) { if(Get-Module -ListAvailable | ? {$_.name -eq "ActiveDirectory"}) { Function New-ADSession { Import-Module ActiveDirectory
} . New-ADSession Write-Host " ActiveDirectory module was imported" } } else { Write-Host " ActiveDirectory module was already imported!" }
if(!(Get-Module -name "ActiveDirectory")) { if(Get-Module -ListAvailable | ? {$_.name -eq "ActiveDirectory"}) {
Function New-ADSession
{
$ADSession = New-PSSession -Authentication CredSSP -cred $ADCreds -ComputerName $dcsvrs[0]
Invoke-Command -Command {Import-Module ActiveDirectory} -Session $ADSession
$null = Import-PSSession -Session $ADSession -AllowClobber -Module ActiveDirectory
}
. New-ADSession Write-Host " ActiveDirectory module was imported" } } else { Write-Host " ActiveDirectory module was already imported!" }