2014-07-21 28 views
1

在我的項目中,我需要Exchange Online Powershell創建Exchange服務帳戶。 下面是代碼示例:如何將新郵件用戶設置爲密碼永不過期

Set-ExecutionPolicy Unrestricted -Force 
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList '[email protected]', $(ConvertTo-SecureString -String '123456' -AsPlainText -Force) 
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection 
Import-PSSession $session 
Enable-OrganizationCustomization 
$exists=Get-MailUser -Identity 'test1' 
if ($exists) {{ 
    remove-mailuser -Identity 'test1' -confirm:$false 
}} 
New-MailUser -Name 'test1' -DisplayName 'test' -MicrosoftOnlineServicesID '[email protected]' -Password $(ConvertTo-SecureString -String '123456' -AsPlainText -Force) 
New-ManagementRoleAssignment -Role 'ApplicationImpersonation' -User 'test1' 
New-ManagementRoleAssignment -Role 'Mailbox Search' -User 'test1' 
Remove-PSSession $session 

我想知道的是: 當密碼過期? 如何將其設置爲永不過期?

回答

1

設置密碼永不過期無法使用Exchange Online的cmdlet,您必須使用Office365的cmdlet(因此MSOnline模塊,http://technet.microsoft.com/en-us/library/jj151815.aspx)。

添加到您的腳本的底部:

Connect-MsolService -Credential $cred 
Get-MSOLUser -SearchString test1 | Set-MsolUser -PasswordNeverExpires $true 
+0

感謝。我知道這種方法。但是,我想知道的是,有一種方法可以通過Exchange Online Powershell而不是MSOnline模塊進行設置。 – Budlion

+0

正如我的答案 - 它是不可能使用Exchange Online cmdlet。 – Raf

相關問題