帮助解决 powershell 错误

发布于 2024-11-28 08:04:22 字数 1056 浏览 0 评论 0原文

我正在尝试运行 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 错误

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

提前致谢。

I am trying to run a powershell script to set user password to never expire in Microsoft BPOS. I got the script from Microsoft support but it doesn't work. I could contact them again to support me but I figure stackoverflow would be faster!

The script I got is:

$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++; 
}

I get prompted for my BPOS credentials (I am an admin) and the error can be seen in the picture:
Powershell error

I am fairly new to powershell so I am not sure how to correct this error, any ideas?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟稳重的好男人 2024-12-05 08:04:22

我认为您通过在脚本中进行格式化尝试一下 $mailboxes 分配:

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

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

I think you're getting bit by formatting in the script try this for the $mailboxes assignment:

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

This should be a single line. If it isn't, pop it into notepad, remove the linebreaks and then copy/paste it into your script (or to the prompt).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文