So I created a Module to connect to my Office 365 Remote PS, and two on-perm PS environments.
I have loaded the Module and ran the three cmdlets that I use to run out of my powershell profile. However now cmdlets like Get-Mailbox are showing up after I connect to the remote PS Environment.
No they are not showing up. Whenever I try to run something that I normally would have ran before when I just had this as a profile script I get an error telling me it’s not recognized.
get-mailbox : The term ‘get-mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
No. Imported modules are always scripts - it’s just a set of proxy functions, not the “real” functions.
So here’s the thing I think you’re running into: scope. Because you’re creating the PSSession within a function, isn’t it likely that the PSSession ceases to exist after the function runs? You can test that by running the function and then running Get-PSSession to see what sessions are available and what their status is. if the session isn’t opened and available, then the proxy module can’t do its job.
Then… not sure. I’d probably try to manually load the proxy module, and look inside it (in the ISE) to make sure it contained the commands I thought it did.
What has to be adjusted to this command to get it to automatically log in: [System.Management.Automation.PsCredential]$Credential = $Host.UI.PromptForCredential(“Enter MSOL Admin Credential”,
“Enter the username and password of an MSOnline Administrator account.”,“”,“userCreds”),