powershell - 如何使用带有自动凭据的 connect-msolservice?
问题描述
顶部代码块不起作用,底部代码块起作用。底部提示典型的 MFA O365 登录窗口“Microsoft 登录电子邮件或电话”(如下图所示),我想使用 cmdlet Connect-MsolService 的凭据参数。我们在这里不使用密码,而是使用证书,因此我想以编程方式将用户电子邮件地址提供给 Connect-MsolService cmdlet,并且不使用密码,就像使用 MFA 登录完成身份验证一样窗户。如何实现?
$adminName = "blah@blah.com";
#$pass = ConvertTo-SecureString "notneeded" -AsPlainText -Force;
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $adminName;
Connect-MsolService -Credential $creds;
$currentDateTime = (GET-DATE);
$lastDirSyncTime =(Get-MsolCompanyInformation).LastDirSyncTime.ToLocalTime();
$timeDifference = $currentDateTime - $lastDirSyncTime;
Write-Host "";
Write-Host "Minutes since the last sync:" $timeDifference.TotalMinutes "minutes.";
下面的工作,但打开如下图所示的 MFA 身份验证窗口,要求输入登录用户名
Connect-MsolService;
$currentDateTime = (GET-DATE);
$lastDirSyncTime =(Get-MsolCompanyInformation).LastDirSyncTime.ToLocalTime();
$timeDifference = $currentDateTime - $lastDirSyncTime;
Write-Host "";
Write-Host "Minutes since the last sync:" $timeDifference.TotalMinutes "minutes.";
解决方案
推荐阅读
- spring-boot - 服务器无法响应同一会话的更多请求
- android - [Swagger][Android] 使用模型生成时的最佳实践
- hadoop - 有没有办法在使用 sqoop 将数据摄取到 hbase 之前处理 sql 表列中的数据
- r - 使用 if 语句出错
- timezone - Flutter 时区(作为 ZoneId)
- javascript - 在运行测试之前等待数据库连接 - 事件问题
- java - 使文本视图全局化
- c# - 获取在 Linq 运行时生成的列的值?
- r - 将列的特定行元素乘以同一数据框中的一组列中的每一列
- java - 当我在主键中共享列(但不仅限于)时如何映射 jpa 实体