Invoking script and trying to run PowerShell commands available in script. Passing credentials from secure credential store as parameters. I am always getting error in this command "connect-msolService -credential $cred"
param([String]$un,
[SecureString]$pwd
)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
#$un = "xxxx@xxx.com"
#$pwd = Read-Host -AsSecureString
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $un,$pwd
Install-Module -Name AzureAD
Install-Module -Name MSOnline -Scope CurrentUser
connect-msolService -credential $cred
Get-MsolAccountSku
In parallel, I tried running these commands manually by passing credentials inside script and it is working fine for me.
Not sure whether issue is due to passing credentials as parameters. i.e. data types of parameters un = string, pwd = SecureString
The 'connect-msolService' command was found in the module 'MSOnline', but the module could not be loaded. For more information, run 'Import-Module MSOnline'.