【发布时间】:2022-08-24 21:43:56
【问题描述】:
我需要在多个 office365 帐户上运行脚本,因此我在一个文件中拥有用户名(电子邮件)和在另一个文件中的密码(所有密码相同)。但我收到此错误消息,并且我没有在帐户上启用 2FA。
Connect-MsolService:身份验证错误:无法完成身份验证请求(可能是代理问题)
这就是整个脚本:
$passwordFile = \"C:\\password.txt\"
$username = \"C:\\users.txt\"
# First time create password file
if (! (Test-Path $passwordFile))
{
Read-Host -AsSecureString | convertfrom-securestring | out-file $passwordFile
}
$password = ConvertTo-SecureString -String $passwordFile -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$licensedUsers = Connect-MsolService -Credential $credential
$licensedUsers = Get-MsolUser -All | ? { $_.UserType -ne \"Guest\" }
$Report = [System.Collections.Generic.List[Object]]::new() # Create output file
Write-Host \"Processing\" $licensedUsers.Count \"accounts...\"
ForEach ($User in $licensedUsers) {
$MFAEnforced = $User.StrongAuthenticationRequirements.State
$MFAPhone = $User.StrongAuthenticationUserDetails.PhoneNumber
$DefaultMFAMethod = ($User.StrongAuthenticationMethods | ? { $_.IsDefault -eq \"True\" }).MethodType
If (($MFAEnforced -eq \"Enforced\") -or ($MFAEnforced -eq \"Enabled\")) {
Switch ($DefaultMFAMethod) {
\"OneWaySMS\" { $MethodUsed = \"One-way SMS\" }
\"TwoWayVoiceMobile\" { $MethodUsed = \"Phone call verification\" }
\"PhoneAppOTP\" { $MethodUsed = \"Hardware token or authenticator app\" }
\"PhoneAppNotification\" { $MethodUsed = \"Authenticator app\" }
}
}
Else {
$MFAEnforced = \"Not Enabled\"
$MethodUsed = \"MFA Not Used\"
}
$ReportLine = [PSCustomObject] @{
User = $User.UserPrincipalName
Name = $User.DisplayName
MFAUsed = $MFAEnforced
MFAMethod = $MethodUsed
PhoneNumber = $MFAPhone
}
$Report.Add($ReportLine)
}
Write-Host \"Report is in c:\\temp\\MFAUsers.CSV\"
$Report | Select User, Name, MFAUsed, MFAMethod, PhoneNumber | Sort Name | Out-GridView
$Report | Sort Name | Export-CSV -NoTypeInformation -Encoding UTF8 c:\\temp\\MFAUsers.csv
-
您将密码文件提供给转换命令,您需要获取密码内容
标签: powershell script