用Windows PowerShell 控制管理 Microsoft Office 365

來源:互聯網
上載者:User

標籤:

如果想要通過PowerShell控制管理Office365,首先要安裝Microsoft Online Services Sign-In Assistant 7.0,連結如下

  • Microsoft Online Services Sign-In Assistant 32-bit
  • Microsoft Online Services Sign-In Assistant 64-bit

之後,安裝Microsoft Online Services Module for Windows PowerShell,連結如下

  • Microsoft Online Services Module for Windows PowerShell 32-bit
  • Microsoft Online Services Module for Windows PowerShell 64-bit

 

如果是管理Office365對應的AD環境,用以下code進行串連:

function connectServer($adminName, $password){    write-host "connecting to outlook.office365.com..."    $O365Cred = New-Object System.Management.Automation.PSCredential($adminName,$password);    $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential$O365Cred -Authentication Basic -AllowRedirection    Import-PSSession $O365Session    Connect-MsolService -Credential $O365Cred}

 

對應的管理AD的users和groups的cmdlet的例子如下:

New-MsolUser -UserPrincipalName $principalName -DisplayName $displayName -PasswordNeverExpires $true -Password $userPasswordNew-MsolGroup -DisplayName $displayName -Description $descriptionAdd-MsolGroupMember -groupObjectid $parentGroup.ObjectId -GroupMemberType "Group" -GroupMemberObjectId $childGroup.ObjectIdaddChildGroup -parent $i -childOfTree $child -groupPrefix $groupPrefix -groupList $groupListAdd-MsolGroupMember -groupObjectid $group.ObjectId -GroupMemberType "User" -GroupMemberObjectId $user.ObjectIdRemove-MsolUser -objectid $ObjectId -forceRemove-MsolGroup -objectid $ObjectId -force

 

如果是管理Office365上面Exchanger,用以下code進行串連:

function connectServer1($adminName, $password){    write-host "connecting to ps.outlook.com..."    Import-Module MSOnline    $sessionOption = New-PSSessionOption -SkipRevocationCheck    $O365Cred = New-Object System.Management.Automation.PSCredential($adminName,$password);    $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection     Import-PSSession $O365Session -AllowClobber     Connect-MsolService -Credential $O365Cred}

 

對應的管理Exchanger的users和groups的cmdlet的例子如下:

New-MsolUser -UserPrincipalName $principalName -DisplayName $displayName -PasswordNeverExpires $true -Password $userPassword -LicenseAssignment $licenses -UsageLocation "US" -forcechangepassword $falseNew-DistributionGroup -Name $name -DisplayName $displayNameNew-DistributionGroup -Name $name -DisplayName $displayName -Type securityAdd-DistributionGroupMember -groupObjectid $parentGroup.ObjectId -GroupMemberType "Group" -GroupMemberObjectId $childGroup.ObjectIdaddDistributionChildGroup -parent $i -childOfTree $child -groupPrefix $groupPrefix -groupList $groupListAdd-DistributionGroupMember -Identity $group.Name -Member $user.NameAdd-DistributionGroupMember -Identity $group2.Name -Member $group.NameRemove-DistributionGroup -Identity $Name -confirm:$falseGet-DistributionGroupMember -Identity $group.name

 

參考資料:

http://blog.crayon.no/blogs/janegil/archive/2011/05/10/administering_2D00_microsoft_2D00_office_2D00_365_2D00_using_2D00_windows_2D00_powershell.aspx

 

用Windows PowerShell 控制管理 Microsoft Office 365

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.