以前管理Office365的時候,需要經常登入背景檢視使用者郵件資訊,配置使用者郵箱屬性等等,下面的腳本可以讓管理者快速登入背景。
方法一:
#region Online-Session
function Online-Session(){
$UserCredential = Get-Credential -Credential [email protected]
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://partner.outlook.cn/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
}
#endregion
方法二:(包含方法一的功能,并且可以管理License,我一直在使用這個)
#region Online-MsolService
function Online-MsolService{
Import-Module MsOnline
$cred=Get-Credential -Credential [email protected]
Connect-MsolService -Credential $cred -errorAction silentlyContinue -errorvariable er
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://partner.outlook.cn/PowerShell-LiveID -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
}
#endregion
轉載于:https://blog.51cto.com/bxing/1877922