Modules loaded in a Function don't exist outside the Function.
i have real-time powershell script talks office365. driven identity management system , invoked through scriptedadapter. ran live@edu.
now office 365 have load msonline module of functionality, not of it. created function load module when needed modules commands , connection msol not exist outside scope of function:
function connecttomsol {
param($creds)
if((get-module | where-object{$_.name -eq "msonline"}) -eq $null){
$error.clear()
import-module msonline
connect-msolservice -credential $creds
if(isnullorempty $error[0] -eq $false){
log "error" ("connection msonline service failed error " + $error[0].message)
}
}
}
it called so:
connecttomsol $o365credentials
once function exists not have cmdlets available me. how can make results of function available outside function?
-- tim
dot sourcing didn't in case. did figure out wrong. in case it's the order in things done. msonline module must loaded before remote session created. once rejigged how , things done it's good. have load module whether need or not. i'll put in initialize logic make determination.
the reason issue find office365 cloud quite slow. can speed things little bit helps. want load modules if need them. being real-time system, can make difference.
thanks answers, info future projects.
-- tim
Windows Server > Windows PowerShell
Comments
Post a Comment