首页 > Windows开发 > 详细

用Windows PowerShell 控制管理 Microsoft Office 365

时间:2015-06-05 19:16:54      阅读:739      评论:0      收藏:0      [点我收藏+]

如果想要通过PowerShell控制管理Office365,首先要安装Microsoft Online Services Sign-In Assistant 7.0,链接如下

之后,安装Microsoft Online Services Module for Windows PowerShell,链接如下

 

如果是管理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 $userPassword

New-MsolGroup -DisplayName $displayName -Description $description

Add-MsolGroupMember -groupObjectid $parentGroup.ObjectId -GroupMemberType "Group" -GroupMemberObjectId $childGroup.ObjectId

addChildGroup -parent $i -childOfTree $child -groupPrefix $groupPrefix -groupList $groupList

Add-MsolGroupMember -groupObjectid $group.ObjectId -GroupMemberType "User" -GroupMemberObjectId $user.ObjectId

Remove-MsolUser -objectid $ObjectId -force

Remove-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 $false

New-DistributionGroup -Name $name -DisplayName $displayName

New-DistributionGroup -Name $name -DisplayName $displayName -Type security

Add-DistributionGroupMember -groupObjectid $parentGroup.ObjectId -GroupMemberType "Group" -GroupMemberObjectId $childGroup.ObjectId

addDistributionChildGroup -parent $i -childOfTree $child -groupPrefix $groupPrefix -groupList $groupList

Add-DistributionGroupMember -Identity $group.Name -Member $user.Name

Add-DistributionGroupMember -Identity $group2.Name -Member $group.Name

Remove-DistributionGroup -Identity $Name -confirm:$false

Get-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

原文:http://www.cnblogs.com/randyyang/p/4264224.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!