【问题标题】:Help with powershell error帮助解决 powershell 错误
【发布时间】:2011-08-09 02:29:50
【问题描述】:

我正在尝试运行 powershell 脚本以在 Microsoft BPOS 中将用户密码设置为永不过期。我从 Microsoft 支持部门获得了脚本,但它不起作用。我可以再次联系他们来支持我,但我认为 stackoverflow 会更快!

我得到的脚本是:

$cred = Get-Credential

$assigned = Get-MSOnlineUser -credential $cred -enabled | where-object { $_.subscriptionids -ge 0 } | Select-Object displayName, identity

$mailboxes = $assigned | foreach-object { Get-XsHostedExchangeMailbox -SourceServer red001.mail.microsoftonline.com -SourceIdentity $_.identity -SourceAdminCredential 

$cred -SourceDetail Full } | select-object DisplayName, identity

$i = 0;
Foreach($element in $assigned) { 
$mailboxes[$i].displayName = $assigned[$i].displayName;
$mailboxes[$i].identity= $assigned[$i].identity;
Set-MSOnlineUserPasswordNeverExpire -identity $mailboxes[$i].identity -passwordNeverExpire $true -Credential $cred 
$i++; 
}

系统提示我输入我的 BPOS 凭据(我是管理员),错误可以在图片中看到: Powershell error

我对 powershell 还很陌生,所以我不知道如何纠正这个错误,有什么想法吗?

提前致谢。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我认为您对脚本中的格式有所了解,试试这个 $mailboxes 分配:

    $mailboxes = $assigned | foreach-object { Get-XsHostedExchangeMailbox -SourceServer red001.mail.microsoftonline.com -SourceIdentity $_.identity -SourceAdminCredential $cred -SourceDetail Full } | select-object DisplayName, identity
    

    这应该是一行。如果不是,请将其弹出到记事本中,删除换行符,然后将其复制/粘贴到您的脚本(或提示符)中。

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多