【发布时间】:2018-08-13 07:17:05
【问题描述】:
我正在努力获取用于创建邮箱、分配许可证等以使用 MFA 的 PowerShell 脚本。
如果我使用这个脚本,只有;
$modules = @(Get-ChildItem -Path "$($env:LOCALAPPDATA)\Apps\2.0" -Filter "Microsoft.Exchange.Management.ExoPowershellModule.manifest" -Recurse )
$moduleName = Join-Path $modules[0].Directory.FullName "Microsoft.Exchange.Management.ExoPowershellModule.dll"
Import-Module -FullyQualifiedName $moduleName -Force
$scriptName = Join-Path $modules[0].Directory.FullName "CreateExoPSSession.ps1"
. $scriptName
$null = Connect-EXOPSSession
$exchangeOnlineSession = (Get-PSSession | Where-Object { ($_.ConfigurationName -eq 'Microsoft.Exchange') -and ($_.State -eq 'Opened') })[0]
我可以使用“获取邮箱”
但是,当我运行与脚本中的函数相同的脚本时;
function O365Logon
{
$modules = @(Get-ChildItem -Path "$($env:LOCALAPPDATA)\Apps\2.0" -Filter "Microsoft.Exchange.Management.ExoPowershellModule.manifest" -Recurse )
$moduleName = Join-Path $modules[0].Directory.FullName "Microsoft.Exchange.Management.ExoPowershellModule.dll"
Import-Module -FullyQualifiedName $moduleName -Force
$scriptName = Join-Path $modules[0].Directory.FullName "CreateExoPSSession.ps1"
. $scriptName
$null = Connect-EXOPSSession
$exchangeOnlineSession = (Get-PSSession | Where-Object { ($_.ConfigurationName -eq 'Microsoft.Exchange') -and ($_.State -eq 'Opened') })[0]
}
我没有收到任何错误,我可以毫无问题地使用 MFA 登录...但是,无法识别 Get-Mailbox。
这是我们脚本中唯一真正调用 O365Logon 的东西;
function Main
{
write-host "`nThis script will create a mailbox in Office 365 for an AD user (with correct attributes), continue? (y/n)."
$response = read-host
if ($response.ToLower() -ne "y"){
Quit
}
O365Logon
return MainMenu
}
非常感谢我能得到的所有帮助。
【问题讨论】:
标签: powershell authentication exchange-server