I am new to advanced PowerShell technologies. I am trying to write my own PS module. I hope I can correctly formulate my problem.
Background:
I created a module of all my frequently used functions called MyTools. A PSM1 file is simply the point source of other PS1 files in the same module folder. At the end of the module, I export the members of the module with Export-ModuleMember -Function * -Alias * -Cmdlet *. (I also created a manifest, but I'm not sure if this matters to my problem.)
One of these functions (called Connect-O365) is defined in one of the PS1 files with dots. This feature automates the connection to a remote PowerShell Office 365. The key parts of the feature are simply:
$O365PS = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $O365URL -Credential $Credential -Authentication Basic -AllowRedirection -Name "O365-$($Credential.UserName)"
Import-PSSession -Session $O365PS -Prefix $CommandPrefix -WarningAction SilentlyContinue -DisableNameChecking
Connect-MsolService -Credential $Credential
"Connect-MSOLService" is another MSOnline module.
Problem . When I open PowerShell, load my module through Import-Module MyTools, then run Connect-O365, the session will be created. I see that an implicit remote access module is being created and commands are being received from the session (at least what the progress bar tells me).
However, none of these Office 365 commands from a remote session are available as soon as this is done. Commands downloaded from local Connect-MSOLserviceare available.
- PS1, Connect-O365, . . , , , . , , PS1, .
MyTools (Export-ModuleMember)?
:
PowerShell 4.0
, , .

2012 ( ): Import-Pssession
Import-Module (Connect-O365) -Global.
PS ( MyTools ), , :
Import-Module (Import-PSSession -Session $O365PS -Prefix $CommandPrefix -WarningAction SilentlyContinue -DisableNameChecking -AllowClobber) -Global
.
[7/23] - ,
*.PSM1 (, TestModule.psm1). "- TestModule"
Function ConnectToAD {
$Sess1 = New-PSSession -ComputerName DC01 -Credential (Get-Credential)
Invoke-Command -Session $Sess1 {Import-Module ActiveDirectory}
Import-PSSession $Sess1 -Prefix Remote -Module ActiveDirectory
}
Export-ModuleMember -Function ConnectToAD
, "Remote" -prefixed .
