Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Is it possible to verify loaded modules in Implicit Remoting session?

$
0
0

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

if(!(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!" }

By loading module via Implicit Remoting session

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!" }


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>