1

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.

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.