当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

作者:精品下载站 日期:2024-12-14 09:04:41 浏览:15 分类:玩电脑

使用 PowerShell 查看 Office 365 对象 |第 2 部分#3


在本文中,我们回顾了使用 PowerShell 在基于 Office 365 的环境中创建“筛选搜索”的各种示例。

使用 PowerShell 查看 Office 365 和 Exchange Online 对象 |系列文章

该系列文章包括以下文章:

  1. 使用 PowerShell“Where 语句”创建过滤搜索 | Office 365 和 Exchange Online 对象
  2. 使用 PowerShell 查看 Office 365 对象(本文)
  3. 使用 PowerShell 查看 Exchange Online 对象

过滤的搜索查询

当前文章中将介绍的示例与“筛选搜索查询”相关,我们需要执行这些示例来获取有关具有特定属性或特定日期/时间值的“特定 Office 365 用户”的信息。

我使用术语基于 Office 365 的环境来表示与存储和管理 Office 365 用户帐户的 Office 365 部分相关的内容。

在基于 Office 365 的环境中,存储 Office 365 用户、组等的 Active Directory 是 Azure Active Directory。

我们在 Azure Active Directory 中引用的主要 PowerShell 对象是“用户对象”。我们用于获取信息和管理 Office 365 用户的 PowerShell cmdlet 是:

Get-MsolUser

我们用于执行“过滤搜索查询”任务的主要工具是 PowerShell cmdlet(语句):

Where-Object

如果您需要有关如何使用 Where-Object PowerShell 命令的更多信息,请阅读当前文章系列中的第一篇文章。

注意:在当前的文章系列中,我们使用较短的形式 -Where(而不是Where-Object)。我们可以用来定义“Where 语句”的另一个选项是使用问号字符“?”而不是“Where”或“Where-Object”。

PowerShell命令Get-MsolUser简介

查看所有 Office 365 用户帐户与默认有限数量

在基于 Office 365 的环境 (Azure Active Directory) 中,我们用于获取有关 Office 365 用户信息的主要 PowerShell 命令是 Get-MsolUser

当我们使用不带任何附加参数的 Get-MsolUser 命令时,Get-MsolUser 命令将显示最多 500 个结果的默认值。

如果您的 Office 365 租户包含大量用户,并且您希望 PowerShell 命令 Get-MsolUser 将获取有关所有现有 Office 365 用户的信息,我们需要添加 PowerShell 参数:

例如:

显示所有 Office 365 用户的列表 |无限制。

Get-MsolUser -All

如何知道在处理 Office 365 用户对象时可以使用哪个筛选参数?

在下面的文章中,我们将回顾创建筛选搜索的不同示例,以查找 Office 365 用户帐户的特定属性

如果我们想要获取特定 PowerShell 对象(例如“Office 365 用户帐户”)的所有可用属性的列表,我们可以使用 Get-Member PowerShell cmdlet。

例如,要获取我们可以查询的PowerShell命令Get-MSolUser的属性(成员)列表,我们可以使用PowerShell命令Get-Member。

我们使用的 PowerShell 语法的示例是:

Get-MSolUser -MaxResults 1 | Get-Member

PowerShell 控制台输出示例:

PS C:\> Get-MSolUser -MaxResults 1 | Get-Member
TypeName: Microsoft.Online.Administration.User

Name                                   MemberType Definition                                                                                                                                        
----                                   ---------- ----------                                                                                                                                        
Equals                                 Method     bool Equals(System.Object obj)                                                                                                                    
GetHashCode                            Method     int GetHashCode()                                                                                                                                 
GetType                                Method     type GetType()                                                                                                                                    
ToString                               Method     string ToString()                                                                                                                                 
AlternateEmailAddresses                Property   System.Collections.Generic.List[string] AlternateEmailAddresses {get;set;}                                                                        
AlternateMobilePhones                  Property   System.Collections.Generic.List[string] AlternateMobilePhones {get;set;}                                                                          
AlternativeSecurityIds                 Property   System.Collections.Generic.List[Microsoft.Online.Administration.AlternativeSecurityId] AlternativeSecurityIds {get;set;}                          
BlockCredential                        Property   System.Nullable[bool] BlockCredential {get;set;}                                                                                                  
City                                   Property   string City {get;set;}                                                                                                                            
CloudExchangeRecipientDisplayType      Property   System.Nullable[int] CloudExchangeRecipientDisplayType {get;set;}                                                                                 
Country                                Property   string Country {get;set;}                                                                                                                         
Department                             Property   string Department {get;set;}                                                                                                                      
DirSyncProvisioningErrors              Property   System.Collections.Generic.List[Microsoft.Online.Administration.DirSyncProvisioningError] DirSyncProvisioningErrors {get;set;}                    
DisplayName                            Property   string DisplayName {get;set;}                                                                                                                     
Errors                                 Property   System.Collections.Generic.List[Microsoft.Online.Administration.ValidationError] Errors {get;set;}                                                
ExtensionData                          Property   System.Runtime.Serialization.ExtensionDataObject ExtensionData {get;set;}                                                                         
Fax                                    Property   string Fax {get;set;}                                                                                                                             
FirstName                              Property   string FirstName {get;set;}                                                                                                                       
ImmutableId                            Property   string ImmutableId {get;set;}                                                                                                                     
IndirectLicenseErrors                  Property   System.Collections.Generic.List[Microsoft.Online.Administration.IndirectLicenseError] IndirectLicenseErrors {get;set;}                            
IsBlackberryUser                       Property   System.Nullable[bool] IsBlackberryUser {get;set;}                                                                                                 
IsLicensed                             Property   System.Nullable[bool] IsLicensed {get;set;}                                                                                                       
LastDirSyncTime                        Property   System.Nullable[datetime] LastDirSyncTime {get;set;}                                                                                              
LastName                               Property   string LastName {get;set;}                                                                                                                        
LastPasswordChangeTimestamp            Property   System.Nullable[datetime] LastPasswordChangeTimestamp {get;set;}                                                                                  
LicenseReconciliationNeeded            Property   System.Nullable[bool] LicenseReconciliationNeeded {get;set;}                                                                                      
Licenses                               Property   System.Collections.Generic.List[Microsoft.Online.Administration.UserLicense] Licenses {get;set;}                                                  
LiveId                                 Property   string LiveId {get;set;}                                                                                                                          
MobilePhone                            Property   string MobilePhone {get;set;}                                                                                                                     
MSExchRecipientTypeDetails             Property   System.Nullable[long] MSExchRecipientTypeDetails {get;set;}                                                                                       
MSRtcSipDeploymentLocator              Property   string MSRtcSipDeploymentLocator {get;set;}                                                                                                       
MSRtcSipPrimaryUserAddress             Property   string MSRtcSipPrimaryUserAddress {get;set;}                                                                                                      
ObjectId                               Property   System.Nullable[guid] ObjectId {get;set;}                                                                                                         
Office                                 Property   string Office {get;set;}                                                                                                                          
OverallProvisioningStatus              Property   Microsoft.Online.Administration.ProvisioningStatus OverallProvisioningStatus {get;set;}                                                           
PasswordNeverExpires                   Property   System.Nullable[bool] PasswordNeverExpires {get;set;}                                                                                             
PasswordResetNotRequiredDuringActivate Property   System.Nullable[bool] PasswordResetNotRequiredDuringActivate {get;set;}                                                                           
PhoneNumber                            Property   string PhoneNumber {get;set;}                                                                                                                     
PortalSettings                         Property   System.Xml.XmlElement PortalSettings {get;set;}                                                                                                   
PostalCode                             Property   string PostalCode {get;set;}                                                                                                                      
PreferredLanguage                      Property   string PreferredLanguage {get;set;}                                                                                                               
ProxyAddresses                         Property   System.Collections.Generic.List[string] ProxyAddresses {get;set;}                                                                                 
ReleaseTrack                           Property   System.Nullable[Microsoft.Online.Administration.O365UserReleaseTrack] ReleaseTrack {get;set;}                                                     
ServiceInformation                     Property   System.Collections.Generic.List[Microsoft.Online.Administration.ServiceInformation] ServiceInformation {get;set;}                                 
SignInName                             Property   string SignInName {get;set;}                                                                                                                      
SoftDeletionTimestamp                  Property   System.Nullable[datetime] SoftDeletionTimestamp {get;set;}                                                                                        
State                                  Property   string State {get;set;}                                                                                                                           
StreetAddress                          Property   string StreetAddress {get;set;}                                                                                                                   
StrongAuthenticationMethods            Property   System.Collections.Generic.List[Microsoft.Online.Administration.StrongAuthenticationMethod] StrongAuthenticationMethods {get;set;}                
StrongAuthenticationPhoneAppDetails    Property   System.Collections.Generic.List[Microsoft.Online.Administration.StrongAuthenticationPhoneAppDetail] StrongAuthenticationPhoneAppDetails {get;set;}
StrongAuthenticationProofupTime        Property   System.Nullable[long] StrongAuthenticationProofupTime {get;set;}                                                                                  
StrongAuthenticationRequirements       Property   System.Collections.Generic.List[Microsoft.Online.Administration.StrongAuthenticationRequirement] StrongAuthenticationRequirements {get;set;}      
StrongAuthenticationUserDetails        Property   Microsoft.Online.Administration.StrongAuthenticationUserDetails StrongAuthenticationUserDetails {get;set;}                                        
StrongPasswordRequired                 Property   System.Nullable[bool] StrongPasswordRequired {get;set;}                                                                                           
StsRefreshTokensValidFrom              Property   System.Nullable[datetime] StsRefreshTokensValidFrom {get;set;}                                                                                    
Title                                  Property   string Title {get;set;}                                                                                                                           
UsageLocation                          Property   string UsageLocation {get;set;}                                                                                                                   
UserLandingPageIdentifierForO365Shell  Property   string UserLandingPageIdentifierForO365Shell {get;set;}                                                                                           
UserPrincipalName                      Property   string UserPrincipalName {get;set;}                                                                                                               
UserThemeIdentifierForO365Shell        Property   string UserThemeIdentifierForO365Shell {get;set;}                                                                                                 
UserType                               Property   System.Nullable[Microsoft.Online.Administration.UserType] UserType {get;set;}                                                                     
ValidationStatus                       Property   System.Nullable[Microsoft.Online.Administration.ValidationStatus] ValidationStatus {get;set;}                                                     
WhenCreated                            Property   System.Nullable[datetime] WhenCreated {get;set;}            

Office 365 用户和许可证信息

在本节中,我们将回顾如何使用 PowerShell 语句 Where 执行过滤搜索,查找有关 Office 365 用户许可证状态的信息。

显示拥有许可证的 Office 365 用户

PowerShell命令语法:

Get-MsolUser -All | Where {$_.isLicensed -eq "True"}

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -All | Where {$_.isLicensed -eq "True"}

UserPrincipalName                   DisplayName           isLicensed
-----------------                   -----------           ----------
[email protected]                   Demi Lovato           True      
[email protected]               Angelina Jolie        True      
[email protected]                 George Michael        True      
[email protected]                  Brad Pitt             True      
[email protected]              onprem300             True      
[email protected]                  James Brown           True      
[email protected]                  Chris Brown           True      
[email protected]                  admin                 True      
[email protected]                Britney Spears        True      
[email protected]                  Nicki Minaj           True      
[email protected]                  Bruno Mars            True      

显示没有许可证的 Office 365 用户

您可以使用以下 PowerShell 命令选项之一:

PowerShell 命令语法(选项 1):

Get-MsolUser -UnlicensedUsersOnly

PowerShell 命令语法(选项 2):

Get-MsolUser -all | Where {$_.isLicensed -ne "TRUE"}

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -UnlicensedUsersOnly

UserPrincipalName               DisplayName                isLicensed
-----------------               -----------                ----------
[email protected]           ADFS_SRV                   False     
[email protected]             ex2007                     False     
[email protected]             ex2013                     False     
[email protected]             ex2010                     False     
[email protected] E-mail attachments Mailbox False     
[email protected]               John Armstrong             False     
[email protected]                 Help desk support tickets  False     
[email protected]          Room-MB01                  False     
[email protected]          Room-MB02                  False     
[email protected]        Shared-MB01                False     
[email protected]        Shared-MB02                False     
[email protected]        DMARC and Spoof E-mail     False     
[email protected]               ab01                       False     
[email protected]             Selena Gomez               False     

显示定义为需要许可证协调的用户的 Office 365 用户

“许可证协调”这个术语不太明确。

简要说明 - 术语“许可证协调”与 Office 365 用户拥有 Exchange Online 邮箱但 Office 365 用户帐户没有有效的 Office 365 的场景相关许可证。

当 Exchange 本地邮箱迁移到“云”(Exchange Online)时,可以在 Exchange 混合等环境中实现这种类型的场景。

当我们迁移 Exchange 本地邮箱时,不会自动分配所需的 Office 365 许可证。

Office 365 用户可以在 30 天的宽限期内访问他的“Exchange Online 邮箱”,尽管他没有 Office 365 许可证。

在这种情况下,Office 365 许可证状态被维护为“许可证协调”。

换句话说,我们需要为许可证状态配置为“许可证协调”的每个 Office 365 用户分配 Office 365 许可证。

我们用于获取此类用户信息的 PowerShell 命令是:

PowerShell命令语法:

Get-MsolUser -LicenseReconciliationNeededOnly

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -LicenseReconciliationNeededOnly

UserPrincipalName      DisplayName isLicensed
-----------------      ----------- ----------
[email protected] userA-001   False     
[email protected]      Mor Danino  False

Office 365 用户 |禁用和启用的用户帐户 + 阻止的用户帐户

显示被视为 - 启用用户的 Office 365 用户

默认情况下,启用 Office 365 用户帐户。

如果我们想要显示启用 Office 365 用户的列表,我们可以使用名为“EnabledOnly”的预定义过滤器。

PowerShell命令语法:

Get-MsolUser -EnabledFilter EnabledOnly -All | FT UserPrincipalName,BlockCredential

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -EnabledFilter EnabledOnly -All | FT UserPrincipalName,BlockCredential

UserPrincipalName              BlockCredential
-----------------              ---------------
[email protected]                      False
[email protected]           False
[email protected]                  False
[email protected]                     False
[email protected]                       False
[email protected]                      False
[email protected]                    False
[email protected]                      False

显示被视为 - 禁用用户的 Office 365 用户

通过 Office 365 管理中心 Web 界面阻止 Office 365 用户的选项被描述为“登录被阻止”。 ”

当使用PowerShell显示“被阻止的用户”列表时,我们使用的参数名为“DisabledOnly”。 ”

PowerShell命令语法:

Get-MsolUser -EnabledFilter DisabledOnly -All | FT UserPrincipalName,BlockCredential

显示被阻止的 Office 365 用户的 PowerShell 命令的另一种变体是:

PowerShell命令语法:

Get-MsolUser | Where {$_.BlockCredential -eq $True} | FT UserPrincipalName,BlockCredential

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.BlockCredential -eq $True} | FT UserPrincipalName,BlockCredential

UserPrincipalName                                            BlockCredential
-----------------                                            ---------------
[email protected]                                                   True
[email protected]                                                      True
[email protected]            True

显示具有特定角色的所有 Office 365 用户

如果您想要获取具有全局管理员角色的 Office 365 用户帐户的列表,您可以使用以下 PowerShell 命令:

$O365ROLE = Get-MsolRole -RoleName "Company Administrator"

Get-MsolRoleMember -RoleObjectId $O365ROLE.ObjectId

PowerShell 控制台输出示例:

Get-MsolRoleMember -RoleObjectId $O365ROLE.ObjectId

RoleMemberType   EmailAddress                    DisplayName    isLicensed
--------------   ------------                    -----------    ----------
ServicePrincipal                                 serviceAccount           
User             [email protected]            Britney        True      
User             [email protected]              Nicki          True      
User             [email protected]              Adele          True      

在特定时间创建的 Office 365 用户

Office 365 (Azure Active Directory) 不提供有关 Office 365 用户登录 Office 365 门户的具体时间的信息。

我们可以“获取”有关 Office 365 用户的唯一“日期/时间信息”是有关创建 Office 365 用户帐户的时间的信息。

在下面的部分中,我想演示各种类型的“日期/时间”PowerShell 查询,我们可以使用它们来“获取”有关在特定时间或特定时间范围内创建的 Office 365 用户的信息。

在我们开始了解有关特定 PowerShell 命令语法的信息之前,让我们花一些时间来了解一下以下概念:使用 PowerShell 查询在特定时间范围内发生的“事件”。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

要创建 PowerShell“基于时间的查询”,我们需要定义以下参数:

1.对象

我们要求获取有关他的信息的具体对象。该对象可以是“用户帐户”、“Exchange 邮箱”等。

2.对象的具体属性

例如,在 Office 365 环境中,我们可以要求获取有关创建 Office 365 用户帐户的特定时间的信息。

在 Office 365 中,我们处理的属性是 WhenCreated

3.时间单位

PowerShell 提供了我们可以使用的各种“时间单位”,例如毫秒、秒、分钟、小时、天、年等。

4. PowerShell 运算符

这是我们使用的特定 PowerShell 运算符。

PowerShell 运算符有多种类型,例如 -lt(小于)、-le(小于或等于)、-gt (大于)、-ge(大于或等于)、-eq (等于)、-ne(不等于)。

在我们的示例中,我将使用以下 PowerShell 运算符演示不同类型的场景:

  • ge(大于或等于)。
  • le(小于或等于)。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

将 PowerShell 运算符与时间范围结合使用

在我们的示例中,我将使用以下两个 PowerShell 运算符演示各种场景:

1.ge(大于或等于)

使用 ge 运算符将帮助我们获取有关从特定时间点及以后发生的事件的信息。

2. le(小于或等于)

使用le运算符将帮助我们获取有关特定时间点之前发生的事件的信息。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

为了能够体现这个概念,让我们使用以下示例:

起点是 PowerShell 命令 Get-Date,它获取当前日期(日、月、年等)。

在我们的具体示例中,我们想要定义当前日期之前两个月的时间范围。

为了定义这个时间范围,我们使用以下 PowerShell 命令:

(Get-Date).AddMonths(-2)

我们获取当前日期,并从当前日期中减去它2 个月

在我们的示例中,当前时间是 8 月(8 月),日期是15

PowerShell 命令 (Get-Date).AddMonths(-2) 的结果将以时间范围的形式实现,涵盖接下来的几个月 - 第 6 个月和第 7 个月,直到当前月份(月8).

如果我们想要更准确,该命令将定义一个时间范围,从06/01开始到08/15结束。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

1.使用 ge(大于或等于)运算符 + 时间范围

当我们使用PowerShell“ge”运算符并结合命令(Get-Date).AddMonths(-2)时,我们要求PowerShell向我们显示信息关于在以下时间范围内发生的事件:06/0108/15

时间范围点的定义方式如下:

时间范围的起点是通过当前日期减去两个月来计算的。

在我们的示例中,起点是6 月份的第一天。

时间范围的“结束”是“当前日期”。

在我们的示例中,当前日期是 8 月的 15 天。

注意 - “当前日期”的值只是我们用于演示的任意值。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

2.使用 le(小于或等于)运算符 + 时间范围

当我们使用 PowerShell“le ”运算符并结合命令 - (Get-Date).AddMonths(-2) 时,我们要求 PowerShell 向我们显示有关之前发生的“事件”的信息。以下时间范围:06/01

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

在以下示例中,我们希望获取有关在特定时间范围内创建的 Office 365 用户帐户的信息。

  1. PowerShell 对象是一个用户帐户。 (由 PowerShell cmdlet Get-MsolUser 表示)。
  2. 特定的用户帐户属性是WhenCreated
  3. 我们使用的时间单位是

为了能够获取回答我们特定查询的 Office 365 用户帐户列表,我们使用名为 Where 的 PowerShell cmdlet(语句)来定义条件并筛选所需信息。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

场景 1:有关过去两个月创建的 Office 365 用户帐户的信息。

为了定义从两个月前开始一直到当前日期的“时间范围”,我们使用 PowerShell 运算符 ge(大于或等于)。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

场景 2:有关过去两个月之前创建的 Office 365 用户帐户的信息。

为了定义从两个月前开始、从当前日期开始并“永远”持续的“时间范围”,我们使用 PowerShell 运算符 - le(小于或等于)。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

根据特定时间范围过滤有关“用户帐户对象”的信息

在下面的部分中,我提供了 PowerShell 命令语法的各种示例,这将帮助我们根据特定时间范围过滤有关“用户帐户对象”的信息。

  • 在第一部分中,我们将查找有关从过去的给定日期到当前日期创建的 Office 365 用户帐户的信息。
  • 在第二部分中,我们将查找有关在特定日期范围之前创建的 Office 365 用户帐户的信息。

显示 Office 365 用户列表 + 有关创建时间的信息 |按创建日期对信息进行排序

PowerShell命令语法:

Get-MsolUser | Sort WhenCreated | Select UserPrincipalName,DisplayName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Sort WhenCreated | Select UserPrincipalName,DisplayName,WhenCreated

UserPrincipalName       DisplayName         WhenCreated          
-----------------       -----------         -----------          
[email protected] Christina Aguilera 12/11/2015 4:44:08 AM 
[email protected]    Justin timberlake  12/11/2015 4:45:35 AM 
[email protected]      Billy              12/11/2015 4:49:58 AM 
[email protected]     Craig David        12/11/2015 4:53:07 AM 
[email protected]   Depeche Mode       12/11/2015 4:57:25 AM 
[email protected]     Elvis Preslay      12/11/2015 5:37:20 AM 
[email protected]    Beyonce            12/11/2015 5:41:22 AM 
[email protected]   Beatles the        12/11/2015 5:45:31 AM 
[email protected]       John Armstrong     4/8/2016 9:39:57 AM   
[email protected]   Angelina Jolie     4/14/2016 6:39:46 AM  
[email protected]    Britney Spears     10/16/2016 3:53:48 AM 
[email protected]     Selena Gomez       10/17/2016 2:03:12 PM 

场景 1#2 - 获取有关在过去 X 个时间范围内创建的 Office 365 用户帐户的信息

在我们的示例中,我们需要“获取”有关“最近”创建的 Office 365 用户帐户的信息。

“最近”一词可以翻译为分钟、小时、周、月或年。

我们定义的 PowerShell“条件”基于 PowerShell 运算符 -ge(大于或等于)。

显示在特定日期之后创建的 Office 365 用户帐户

在以下示例中,我们希望获取有关在 2016 年 11 月 10 日或该日期之后创建的 Office 365 用户帐户的信息。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge "11/10/2016"} | Select UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.WhenCreated -ge "11/10/2016"} |  Select UserPrincipalName,WhenCreated 

UserPrincipalName        WhenCreated           
-----------------        -----------           
[email protected]        12/13/2016 11:22:17 AM
[email protected] 11/28/2016 1:30:42 PM 
[email protected] 11/28/2016 1:31:16 PM 
[email protected] 11/28/2016 1:31:46 PM 
[email protected]     12/13/2016 11:21:41 AM
[email protected]      12/06/2016 7:45:23 AM 
[email protected]        12/15/2016 1:01:42 PM 
[email protected] 11/28/2016 1:32:30 PM 
[email protected]      12/18/2016 6:59:28 AM 
[email protected] 11/28/2016 1:29:30 PM 
[email protected]         11/17/2016 5:39:09 PM 

显示过去 X 分钟内创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关过去160 分钟内创建的 Office 365 用户帐户的信息。

为了定义以分钟为单位的范围,我们使用 PowerShell 参数 - Addminutes。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).Addminutes(-160))} | Select UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\>  Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).Addminutes(-160))} | Select UserPrincipalName,WhenCreated

UserPrincipalName      WhenCreated           
-----------------      -----------           
[email protected]      12/13/2016 11:22:17 AM
[email protected]   12/13/2016 11:21:41 AM
[email protected]      12/15/2016 1:01:42 PM 
[email protected]    12/18/2016 6:59:28 AM 
[email protected] 12/14/2016 12:07:59 PM

显示过去 X 小时内创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关过去 40 小时内创建的 Office 365 用户帐户的信息。

为了定义以小时为单位的范围,我们使用 PowerShell 参数 - AddHours。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).AddHours(-40))} | Select UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).AddHours(-40))} | Select UserPrincipalName,WhenCreated 

UserPrincipalName      WhenCreated           
-----------------      -----------           
[email protected]      12/13/2016 11:22:17 AM
[email protected]   12/13/2016 11:21:41 AM
[email protected]    12/06/2016 7:46:55 AM 
[email protected]    12/06/2016 7:45:23 AM 
[email protected]      12/15/2016 1:01:42 PM 
[email protected]    12/18/2016 6:59:28 AM 
[email protected] 12/14/2016 12:07:59 PM

显示过去 X 天内创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关过去 40 天内创建的 Office 365 用户帐户的信息。

为了定义以天为单位的范围,我们使用 PowerShell 参数 - Adddays。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).Adddays(-40))} | FT UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).Adddays(-40))} | FT UserPrincipalName,WhenCreated 

UserPrincipalName        WhenCreated           
-----------------        -----------           
[email protected]        12/13/2016 11:22:17 AM
[email protected] 11/28/2016 1:31:16 PM 
[email protected] 11/28/2016 1:31:46 PM 
[email protected]     12/13/2016 11:21:41 AM
[email protected]   12/01/2016 8:46:47 AM 
[email protected]      12/06/2016 7:46:55 AM 
[email protected]      12/06/2016 7:45:23 AM 
[email protected]      12/18/2016 6:59:28 AM 
[email protected] 11/28/2016 1:29:30 PM 
[email protected]         11/17/2016 5:39:09 PM 

显示过去 X 个月内创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关过去2 个月创建的 Office 365 用户帐户的信息。

为了定义以月为单位的范围,我们使用 PowerShell 参数 - AddMonths。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated

显示在特定月份创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关在特定月份创建的 Office 365 用户帐户的信息。我们使用的月份是 - 八月 (8)

PowerShell命令语法:

Get-MsolUser | Where-Object {($_.WhenCreated).Month -eq 8} | Select UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {($_.WhenCreated).Month -eq 8} | Select UserPrincipalName,WhenCreated

UserPrincipalName        WhenCreated          
-----------------        -----------          
[email protected] 08/27/2016 7:11:53 PM
[email protected] 08/27/2016 5:41:50 PM
[email protected]     08/30/2016 4:46:40 AM
[email protected]   08/27/2016 4:29:18 AM
[email protected]   08/25/2016 5:25:29 PM

显示过去 X 年内创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关过去 2 年创建的 Office 365 用户帐户的信息。

为了定义以年为单位的范围,我们使用 PowerShell 参数 - AddYears。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).AddYears(-2))} | FT UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.WhenCreated -ge ((Get-Date).AddYears(-2))} | FT UserPrincipalName,WhenCreated

UserPrincipalName     WhenCreated           
-----------------     -----------           

[email protected]     12/13/2016 11:22:17 AM
[email protected] 04/14/2016 6:39:46 AM 
[email protected]   09/24/2016 5:28:58 PM 
[email protected]    09/12/2016 6:01:09 AM 
[email protected]    10/23/2016 8:58:41 PM 
[email protected]    10/22/2015 3:31:34 AM 
[email protected]  10/16/2015 3:53:48 AM

显示在特定年份创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关 2016 年创建的 Office 365 用户帐户的信息。

PowerShell命令语法:

Get-MsolUser | Where {($_.WhenCreated).Year -eq 2016} | select UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {($_.WhenCreated).Year -eq 2016} | select UserPrincipalName,WhenCreated

UserPrincipalName     WhenCreated           
-----------------     -----------           
[email protected]     12/13/2016 11:22:17 AM
[email protected] 04/14/2016 6:39:46 AM 
[email protected]   09/24/2016 5:28:58 PM 
[email protected]    09/12/2016 6:01:09 AM 
[email protected]    10/23/2016 8:58:41 PM 
[email protected]    10/22/2016 3:31:34 AM 
[email protected]  10/16/2016 3:53:48 AM 
[email protected]    10/25/2016 7:38:53 PM 
[email protected]    10/22/2016 3:31:34 AM

场景 2#2 - 获取有关在特定时间范围之前创建的 Office 365 用户帐户的信息

在当前场景中,我们需要获取有关在特定时间范围之前创建的 Office 365 用户帐户的信息(与之前的场景相比,我们查找在特定时间范围内创建的用户帐户)指定的时间范围)。

我们定义的时间范围是从当前日期算起的两个月。

我们想要获取的信息是有关在此时间范围之前创建的 Office 365 用户帐户的信息。

例如,如果当前日期是 12/15/2016,结果将为 - 在该日期之前创建的所有 Office 365 用户帐户 - 10/01/2016嗯>。

为了能够满足此要求,我们使用 PowerShell 运算符 - le(小于或等于)。

显示 X 天前创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关在“40 天”或更长的时间范围之前创建的 Office 365 用户帐户的信息。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -le ((Get-Date).Adddays(-40))} | FT UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\>  Get-MsolUser | Where {$_.WhenCreated -le ((Get-Date).Adddays(-40))} | FT UserPrincipalName,WhenCreated

UserPrincipalName     WhenCreated           
-----------------     -----------           
[email protected] 04/14/2016 6:39:46 AM 
[email protected]   09/24/2016 5:28:58 PM 
[email protected]    09/12/2016 6:01:09 AM 
[email protected]    10/23/2016 8:58:41 PM 
[email protected]    10/22/2016 3:31:34 AM 
[email protected]    10/22/2016 3:31:34 AM

显示 X 个月前创建的 Office 365 用户帐户列表

在以下示例中,我们希望获取有关在“2 个月”或更长的时间范围之前创建的 Office 365 用户帐户的信息。

PowerShell命令语法:

Get-MsolUser | Where {$_.WhenCreated -Le ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.WhenCreated -Le ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated

UserPrincipalName     WhenCreated           
-----------------     -----------           
[email protected] 04/14/2016 6:39:46 AM 
[email protected]   09/24/2016 5:28:58 PM 
[email protected]    09/12/2016 6:01:09 AM 
[email protected]    10/22/2016 3:31:34 AM 
[email protected]  10/16/2016 3:53:48 AM 
[email protected]    10/22/2016 3:31:34 AM 

显示 UPN 名称包含特定域名的 Office 365 用户

任务 - 显示 UPN(用户主体名称)后缀包含特定域名的 Office 365 用户帐户列表。

在以下示例中,我们查找 UPN 名称后缀包含特定域名的 Office 365 用户 - o365info.com

PowerShell命令语法:

Get-MsolUser | Where {$_.UserPrincipalName -like "*@o365info.com"}

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.UserPrincipalName -like "*@o365info.com"} 

UserPrincipalName               DisplayName                isLicensed
-----------------               -----------                ----------
[email protected]               Demi Lovato                True      
[email protected]           Angelina Jolie             True      
[email protected]             George Michael             True      
[email protected]              Brad Pitt                  True      
[email protected]        Shared-MB04                False     
[email protected]              James Brown                True      
[email protected]              Chris Brown                True      
[email protected]           ADFS_SRV                   False     
[email protected]            Britney Spears             True      
[email protected]              Nicki Minaj                True      
[email protected]              Bruno Mars                 True      

显示软删除的 Office 365 用户

在Azure Active Directory环境中,当我们删除Office 365用户帐户时,该用户帐户并没有被永久删除,而是“发送”到了Azure Active Directory回收站。

我们将已删除的对象在 Azure Active Directory 中保留 30 天。

在这种情况下,我们要求过滤搜索结果,指定我们只想获取有关已删除的 Office 365 帐户的信息。

描述已删除用户帐户的技术术语是“软删除”。

PowerShell命令语法:

Get-MsolUser -ReturnDeletedUsers

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -ReturnDeletedUsers 


UserPrincipalName                                          DisplayName                                   isLicensed
-----------------                                          -----------                                   ----------
[email protected] HealthMailbox-STS-ex2013                      False     
[email protected] HealthMailbox-STS-Mailbox-Database-1713880035 False     
[email protected]                                       Test100                                       True

显示具有特定使用位置值的 Office 365 用户

显示所有没有使用位置的 Office 365 用户

PowerShell命令语法:

Get-MsolUser | Where {$_.UsageLocation -eq $Null} | Select UserPrincipalName,UsageLocation

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.UsageLocation -eq $Null} | Select UserPrincipalName,UsageLocation 

UserPrincipalName                   UsageLocation
-----------------                   -------------
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

显示具有使用位置特定使用位置的所有 Office 365 用户

在以下示例中,我们希望获取使用位置为 - GB(英国)的 Office 365 用户的列表。

PowerShell命令语法:

Get-MsolUser | Where {$_.UsageLocation -eq "gb"} | Select UserPrincipalName,UsageLocation

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.UsageLocation -eq "gb"} | Select UserPrincipalName,UsageLocation 

UserPrincipalName     UsageLocation
-----------------     -------------
[email protected]    GB           
[email protected] GB

显示具有特定密码设置的 Office 365 用户

在本节中,我们将回顾如何执行 PowerShell 查询来查找 Office 365 用户密码的特定“状态”。

显示密码设置为永不过期的所有 Office 365 用户

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.PasswordNeverExpires -eq $True} | Select UserPrincipalName,PasswordNeverExpires

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.PasswordNeverExpires -eq $True} | Select UserPrincipalName,PasswordNeverExpires

UserPrincipalName          PasswordNeverExpires
-----------------          --------------------
[email protected]      True
[email protected]        True
[email protected]         True
[email protected]       True
[email protected]         True
[email protected]         True
[email protected]        True
[email protected]       True

显示密码设置为过期的 Office 365 用户

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.PasswordNeverExpires -eq $False} | Select UserPrincipalName,PasswordNeverExpires

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.PasswordNeverExpires -eq $False} | Select UserPrincipalName,PasswordNeverExpires

UserPrincipalName              PasswordNeverExpires
-----------------              --------------------
[email protected]                             False
[email protected]                            False
[email protected]                      False
[email protected]                      False
[email protected]                          False
[email protected]                      False
[email protected]                           False
[email protected]                           False
[email protected]                      False

显示过去 X 个月内更改密码的 Office 365 用户

在上一节中,我们回顾了可用于执行筛选搜索、查找有关特定 Office 365 用户帐户“创建时间”的信息的各种选项。

相同的 PowerShell 语法可用于获取有关 Office 365“上次”更改密码的信息。

我们查询的 Office 365 用户属性是 lastpasswordchangetimestamp

我们创建的过滤搜索可以提出两个主要问题:

问题 1:有关在过去 X 天、一周等时间内“更改”密码的 Office 365 用户的信息。

这个“问题”的目的是获取有关在特定时间范围内“执行”密码更改的 Office 365 用户的信息。

我们用于获取有关此类“问题”信息的 PowerShell 运算符是 - ge(大于或等于)。

问题 2:有关在过去 X 天、一周等时间内未“更改”密码的 Office 365 用户的信息。

这个“问题”的目的是获取Office 365用户的信息,他们的密码即将过期等。

我们用于获取有关此类“问题”信息的 PowerShell 运算符是 - le(小于或等于)。

示例 1 - 查找过去 2 个月内更新过密码的 Office 365 用户

PowerShell命令语法:

Get-MsolUser | Where {$_.lastpasswordchangetimestamp -ge ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated,lastpasswordchangetimestamp

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.lastpasswordchangetimestamp -ge ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated,lastpasswordchangetimestamp 

UserPrincipalName        WhenCreated            LastPasswordChangeTimestamp
-----------------        -----------            ---------------------------
[email protected]        12/13/2016 11:22:17 AM 12/13/2016 11:29:44 AM     
[email protected]       09/12/2016 6:01:09 AM  10/23/2016 7:43:31 AM      
[email protected]       10/25/2016 7:38:53 PM  11/20/2016 2:57:29 PM      
[email protected]       10/22/2016 3:31:34 AM  10/25/2016 6:26:43 PM      
[email protected] 11/28/2016 1:31:16 PM  11/28/2016 1:37:39 PM      
[email protected]       11/01/2016 3:50:05 PM  12/11/2016 6:59:38 PM      

示例 2 - 查找在过去 2 个月内未更新密码的 Office 365 用户

PowerShell命令语法:

Get-MsolUser | Where {$_.lastpasswordchangetimestamp -le ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated,lastpasswordchangetimestamp

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.lastpasswordchangetimestamp -le ((Get-Date).AddMonths(-2))} | FT UserPrincipalName,WhenCreated,lastpasswordchangetimestamp

UserPrincipalName     WhenCreated            LastPasswordChangeTimestamp
-----------------     -----------            ---------------------------
[email protected] 04/14/2016 6:39:46 AM  09/15/2016 2:52:33 PM      
[email protected]   09/24/2016 5:28:58 PM  09/24/2016 5:26:38 PM      
[email protected]    10/22/2016 3:31:34 AM  10/22/2016 3:29:24 AM      
[email protected]  10/16/2016 3:53:48 AM  10/16/2016 3:51:57 AM      
[email protected]   10/17/2016 2:03:12 PM  10/17/2016 1:58:12 PM      
[email protected]    09/21/2016 9:59:02 AM  09/21/2016 9:56:07 AM

显示具有特定“用户详细信息”的 Office 365 用户

在本节中,我想回顾一下我们想要执行 PowerShell 查询的场景,查找具有特定“用户详细信息”(例如部门、城市、国家/地区等)的 Office 365 用户帐户。

1#2 - 使用 Get-MsolUser“过滤器”选项

PowerShell 命令 Get-MsolUser 包含“内置过滤器”,我们可以将其添加到 Get-MsolUser 命令中。

在下面的屏幕截图中,我们可以看到可以添加到 Get-MsolUser 命令的“内置过滤器”的示例。

[玩转系统] 使用 PowerShell 查看 Office 365 对象 |第 2 部分#3

我们可以与 Get-MsolUser 命令组合使用的“内置过滤器”是:

  • 国家
  • 状态
  • 城市
  • 部门
  • 标题

使用“内置过滤器”的缺点是,此类过滤器的数量有限,如果我们想要查询另一个或其他 Office 365 用户帐户属性,我们不能依赖这些内置过滤器。 ”

附件是我们需要使用的 PowerShell 语法的一些示例,以防我们想要将内置过滤器与 Get-MsolUser 命令结合使用。

显示国家/地区等于 X 的 Office 365 用户列表

在以下示例中,我们希望获取国家/地区=美国的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser -Country USA |FT UserPrincipalName,DisplayName,Country

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -Country USA |FT UserPrincipalName,DisplayName,Country 

UserPrincipalName    DisplayName Country
-----------------    ----------- -------
[email protected] Beyonce     USA

显示状态等于 X 的 Office 365 用户

在以下示例中,我们希望获取州=亚利桑那州的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser -State Arizona | FT UserPrincipalName,DisplayName,State

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -State Arizona | FT UserPrincipalName,DisplayName,State

UserPrincipalName    DisplayName State
-----------------    ----------- -----------
[email protected] Beyonce      

显示城市等于 X 的 Office 365 用户

在以下示例中,我们希望获取 City=New York 的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser -city "New York" | FT UserPrincipalName,DisplayName,city

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -city "New York" | FT UserPrincipalName,DisplayName,city

UserPrincipalName    DisplayName City    
-----------------    ----------- ----    
[email protected] Beyonce     New York
[email protected]   Grace jones New York

显示部门等于 X 的 Office 365 用户的列表

在以下示例中,我们希望获取Department= Marketing 的 Office 365 用户列表。

Get-MsolUser -Department Marketing | FT UserPrincipalName,DisplayName,Department

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -Department Marketing | FT UserPrincipalName,DisplayName,Department

UserPrincipalName     DisplayName    Department
-----------------     -----------    ----------
[email protected]   Craig David    Marketing 
[email protected]  Beyonce        Marketing 
[email protected] Beatles the    Marketing 
[email protected] Angelina Jolie Marketing1

显示标题等于 X 的 Office 365 用户

在以下示例中,我们希望获取 Title=VIP 的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser -Title vip | FT UserPrincipalName,DisplayName,Title

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser -Title vip | FT UserPrincipalName,DisplayName,Title

UserPrincipalName    DisplayName Title
-----------------    ----------- -----
[email protected] Beyonce     VIP  

2#2 - 使用 PowerShellWhere 语句过滤搜索结果

在下一节中,我想回顾一下我们可以使用的其他选项,以防我们需要创建一个过滤搜索来“过滤”Office 365 用户帐户,并使用特定的“用户详细信息”。

搜索过滤器是通过使用 PowerShell Where 语句来实现的,我们已经在当前文章的前面部分中使用过该语句。

PowerShell Where 语句的优点是,我们可以使用此选项创建与“其他用户帐户详细信息”相关的过滤器搜索,而使用内置过滤器时不会包含这些详细信息”组合 Get-MsolUser 命令。

显示国家/地区等于 X 的 Office 365 用户列表

在以下示例中,我们希望获取国家/地区=美国的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser | Where {$.Country -eq "USA"} | FT UserPrincipalName,DisplayName,Country

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$.Country -eq "USA"} | FT UserPrincipalName,DisplayName,Country 

UserPrincipalName    DisplayName Country
-----------------    ----------- -------
[email protected] Beyonce     USA

显示状态等于 X 的 Office 365 用户

在以下示例中,我们希望获取州=亚利桑那州的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser | Where {$.State -eq "Arizona"} | FT UserPrincipalName,DisplayName,State

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$.State -eq "Arizona"} | FT UserPrincipalName,DisplayName,State

UserPrincipalName    DisplayName State
-----------------    ----------- -----------
[email protected] Beyonce   

显示城市等于 X 的 Office 365 用户

在以下示例中,我们希望获取 City=New York 的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser | Where {$.city -eq "New York"} | FT UserPrincipalName,DisplayName,City

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$.city -eq "New York"} | FT UserPrincipalName,DisplayName,City

UserPrincipalName    DisplayName City    
-----------------    ----------- ----    
[email protected] Beyonce     New York
[email protected]   Grace jones New York

显示部门等于 X 的 Office 365 用户的列表

在以下示例中,我们希望获取Department= Marketing 的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser | Where {$.Department -eq "Marketing"} |FT UserPrincipalName,DisplayName,Department

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$.Department -eq "Marketing"} |FT UserPrincipalName,DisplayName,Department

UserPrincipalName     DisplayName    Department
-----------------     -----------    ----------
[email protected]   Craig David    Marketing 
[email protected]  Beyonce        Marketing 
[email protected] Beatles the    Marketing 
[email protected] Angelina Jolie Marketing1

显示标题等于 X 的 Office 365 用户

在以下示例中,我们希望获取 Title=VIP 的 Office 365 用户列表。

PowerShell命令语法:

Get-MsolUser | Where {$.title -eq "vip"} | FT UserPrincipalName,DisplayName,Title

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$.title -eq "vip"} | FT UserPrincipalName,DisplayName,Title

UserPrincipalName    DisplayName Title
-----------------    ----------- -----
[email protected] Beyonce     VIP  

在下一节中,我想回顾一下其他示例,其中我们使用 PowerShell Where 语句来执行有关 Office 365 用户帐户详细信息的查询。

显示办公室电话号码以 X 前缀开头的 Office 365 用户

在以下示例中,我们希望获取 Office 365 用户的列表,其办公室电话号码以以下前缀+1开头。

在这种情况下,我们使用 PowerShell 运算符“like”,因为我们不寻找“完美匹配”。 ”

相反,我们希望获取有关所有 Office 365 用户的信息,即他们的办公室电话号码以我们要查找的特定字符(在我们的场景中为 +1)开头,但我们不知道是什么办公室电话号码的“其余”是。

为了定义搜索过滤器,我们使用以下语法 - “+1*

PowerShell命令语法:

Get-MsolUser | Where {$_.PhoneNumber -like "+1*"} |FT UserPrincipalName,DisplayName,PhoneNumber

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {$_.PhoneNumber -like "+1*"} |FT UserPrincipalName,DisplayName,PhoneNumber

UserPrincipalName     DisplayName PhoneNumber     
-----------------     ----------- -----------     
[email protected]  Beyonce     +16565656878    
[email protected] Beatles the +178479487498479

显示其部门等于 X + 以 X 前缀开头的办公室电话号码的 Office 365 用户

在此示例中,我们创建一个“组合”两个不同字符的 PowerShell 查询。

显示 Office 365 用户列表,其部门=营销 + 办公室电话号码以以下前缀 +1 开头。

PowerShell命令语法:

Get-MsolUser | Where {($_.Department -eq "Marketing") -and ($_.PhoneNumber -like "+1*")} | FT UserPrincipalName,DisplayName,Department,PhoneNumber

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where {($_.Department -eq "Marketing") -and ($_.PhoneNumber -like "+1*")} | FT UserPrincipalName,DisplayName,Department,PhoneNumber

UserPrincipalName     DisplayName Department PhoneNumber     
-----------------     ----------- ---------- -----------     
[email protected]  Beyonce     Marketing  +16565656878    
[email protected] Beatles the Marketing  +178479487498479

Office 365 用户组

显示所有 Office 365 用户组的列表

PowerShell命令语法:

Get-MsolGroup

PowerShell 控制台输出示例:

PS C:\> Get-MsolGroup

ObjectId                               DisplayName                                                              GroupType                                                                Description                                                             
--------                               -----------                                                              ---------                                                                -----------                                                             
402442d9-bf87-4f13-9a29-0cd79b10d89b   View-Only Organization Management                                        Security                                                                 Members of this management role group can view recipient and configur...
13cda959-ae4d-43e1-9095-207b17b780ad   Public Folder Management                                                 Security                                                                 Members of this management role group can manage public folders. Memb...
503bfc1a-19fa-4e9f-ace3-6bce1b7ac1e7   Exchange Servers                                                         Security                                                                 This group contains all the Exchange servers. This group shouldn't be...
649ebbdc-1965-4dc2-af1a-07edb351f19b   UM Management                                                            Security                                                                 Members of this management role group can manage Unified Messaging or...
87e3661f-4b51-4d78-85ba-079e338ff3fb   Delegated Setup                                                          Security                                                                 Members of this management role group have permissions to install and...
f5983045-486d-4585-a3f7-2434295ba55d   Server Management                                                        Security                                                                 Members of this management role group have permissions to manage all ...
6e0a2cb5-446f-4564-8b3d-db551f90be45   Exchange Windows Permissions                                             Security                                                                 This group contains Exchange servers that run Exchange cmdlets on beh...
cc4ee22e-6eb2-4866-88d4-ed6f69c6ffd5   Recipient Management                                                     Security                                                                 Members of this management role group have rights to create, manage, ...
3605cfea-0179-489e-b821-ddf6a24ba936   Records Management                                                       Security                                                                 Members of this management role group can configure compliance featur...
9b46a230-3511-4524-90d3-6d7f6a5d056f   Hygiene Management                                                       Security                                                                 Members of this management role group can manage Exchange anti-spam f...
3694e548-3309-4ba5-b248-2cca0dbbdc64   Organization Management                                                  Security                                                                 Members of this management role group have permissions to manage Exch...
a4894293-1f39-4f61-b61b-0691b3526d2b   Discovery Management                                                     Security                                                                 Members of this management role group can perform searches of mailbox...
70350ae9-91a1-4349-959a-88ea5f9673be   Exchange Install Domain Servers                                          Security                                                                 This group is used during Exchange setup and is not intended to be us...
9ac0234e-e422-4e33-a724-5a4f6a5405bf   Exchange Trusted Subsystem                                               Security                                                                 This group contains Exchange servers that run Exchange cmdlets on beh...
96fee0cf-0355-4b30-98bc-e4fd7e9e0b14   Server Management                                                        Security                                                                 Members of this management role group have permissions to manage all ...
ad18cc59-be88-462f-a4d7-746b5a6d5df7   View-Only Organization Management                                        Security                                                                 Members of this management role group can view recipient and configur...
7d3fa6f6-9619-46e6-aa2e-50bb21d3a48b   Discovery Management                                                     Security                                                                 Members of this management role group can perform searches of mailbox...
a954e55d-824c-4bc3-8dd0-7c928e72a0ca   Delegated Setup                                                          Security                                                                 Members of this management role group have permissions to install and...
6b4f2967-9480-4488-9db2-214d1a4c9bee   Organization Management                                                  Security                                                                 Members of this management role group have permissions to manage Exch...
744fe39b-65b4-41d8-bb4b-cafe9559d59d   Public Folder Management                                                 Security                                                                 Members of this management role group can manage public folders. Memb...
3566a9cb-4624-4f03-a668-0309901d6d3e   Exchange Windows Permissions                                             Security                                                                 This group contains Exchange servers that run Exchange cmdlets on beh...
27a9316e-8823-48a0-bcb5-ef02d260acba   Exchange Servers                                                         Security                                                                 This group contains all the Exchange servers. This group shouldn't be...
e6497af5-bfe2-474a-afa8-dd4532fa1d83   UM Management                                                            Security                                                                 Members of this management role group can manage Unified Messaging or...
dc1c3eb4-24ca-4989-821b-d307cece984c   Records Management                                                       Security                                                                 Members of this management role group can configure compliance featur...
e1f81ca5-eeac-4b42-8f57-05e7a1630bc1   Hygiene Management                                                       Security                                                                 Members of this management role group can manage Exchange anti-spam f...
0c2ad240-4327-4bd9-870d-9a329bd74c85   Recipient Management                                                     Security                                                                 Members of this management role group have rights to create, manage, ...
32640e8f-6de4-4d36-b09e-da0db33123f3   Exchange Trusted Subsystem                                               Security                                                                 This group contains Exchange servers that run Exchange cmdlets on beh...
9e8d94f9-9887-4d50-bb23-a51f10cf1d7f   Exchange Install Domain Servers                                          Security                                                                 This group is used during Exchange setup and is not intended to be us...
261e42b9-8798-416c-8656-0ac7d9344341   DnsUpdateProxy                                                           Security                                                                 DNS clients who are permitted to perform dynamic updates on behalf of...
c808c391-df6e-4145-9e8d-8fe2ddfd993f   ExchangeLegacyInterop                                                    Security                                                                 This group is for interoperability with Exchange 2003 servers within ...
0a21289c-1bb4-4780-a4a5-ad83679add07   DnsAdmins                                                                Security                                                                 DNS Administrators Group                                                
88c37cd1-864f-415d-a18f-ec7b979da573   Exchange All Hosted Organizations                                        Security                                                                 This group contains all the Exchange Hosted Organization Mailboxes gr...
1d101e1e-2821-4264-8d2a-8afd9f4757b9   Discovery Management                                                     Security                                                                 Members of this management role group can perform searches of mailbox...
4a95ed71-924c-4503-b228-eea30b2a9222   UM Management                                                            Security                                                                 Members of this management role group can manage Unified Messaging or...
9688fd5d-d427-4876-911d-96b0cf8cb599   Records Management                                                       Security                                                                 Members of this management role group can configure compliance featur...
5ea09528-0dba-4a08-9983-364c1728a18e   Recipient Management                                                     Security                                                                 Members of this management role group have rights to create, manage, ...
edf56ebf-a15e-4125-a82c-264a2dff129e   Server Management                                                        Security                                                                 Members of this management role group have permissions to manage all ...
a1e70fbc-4516-4d8c-98bf-dade43743378   View-Only Organization Management                                        Security                                                                 Members of this management role group can view recipient and configur...
e532c0f6-899d-4d85-9d52-c4f28b0c26ed   Exchange Public Folder Administrators                                    Security                                                                 Users in this group can manage Exchange public folder attributes in t...
e58de916-39aa-46ca-91d1-f44d6fe526e9   Hygiene Management                                                       Security                                                                 Members of this management role group can manage Exchange anti-spam f...
d9c21663-42c3-43a3-824f-5901ce76866d   Exchange View-Only Administrators                                        Security                                                                 Users in this group will have permission to read all Exchange configu...
eac84f53-d9cb-4f48-97ca-cbf4476b841c   Organization Management                                                  Security                                                                 Members of this management role group have permissions to manage Exch...
c5e0fdcd-c550-4b1b-a8f1-ce1b9f3a29f0   Exchange Servers                                                         Security                                                                 This group contains all the Exchange servers. This group should not b...
c1322bb7-7b01-42c2-8658-9737be7df7d4   Exchange Windows Permissions                                             Security                                                                 This group contains Exchange servers that run Exchange cmdlets on beh...
de10804d-3dca-4d97-8db6-db8321fb4060   Public Folder Management                                                 Security

出现错误的 Office 365 用户

术语“错误”可用于描述 Office 365 环境中许多不同类型的“用户错误”。

例如:

  • 由于无法将 Office 365 用户详细信息(来自 Azure Active Directory 的信息)同步到 Exchange Online 基础结构而导致的预配错误。
  • Office 365 许可证错误。
  • 恢复 Office 365 用户帐户失败。

显示有错误的 Office 365 用户帐户列表

如果我们想要获取“有错误的 Office 365 用户帐户”列表,我们可以使用名为 HasErrorsOnly 的“内置”过滤器,该过滤器可与 PowerShell cmdlet - Get-MsolUser 一起使用。

PowerShell命令语法:

Get-MsolUser -HasErrorsOnly | FL Alias,Errors

显示有错误的 Office 365 用户帐户列表 + 有关特定错误的详细信息

我们可以用来获取“出现错误的 Office 365 用户帐户”列表以及有关特定错误的详细信息的其他类型的 PowerShell 命令是:

(Get-MsolUser -HasErrorsOnly).Errors.errordetail.objecterrors.errorrecord | FL

获取包含验证错误的 Office 365 列表

Office 365 环境中的另一种“Office 365 用户帐户错误”被描述为 ValidationStatus 错误。

要获取有关出现此类错误的 Office 365 用户帐户的信息,我们可以使用 PowerShell 查询,该查询会查找 ValidationStatus 值等于错误的 Office 365 用户。

Get-MsolUser | Where-Object {$_.ValidationStatus -eq "Error"} | Select UserPrincipalName,ValidationStatus,Errors

Office 365 用户和目录同步环境

在本节中,我们将回顾如何使用 PowerShell 命令执行筛选搜索,以获取有关被视为“同步用户”的 Office 365 用户的各种类型的信息。

术语“同步用户”与组织使用 Azure AD Connect 将本地 Active Directory 用户同步到“云”(Azure Active Directory)的场景相关。

Office 365 目录可以包含“本机 Office 365 用户帐户”+“同步用户帐户”的“混合”。

显示被视为非同步用户的 Office 365 用户帐户列表

在以下示例中,我们希望获取未同步用户(在云中)的 Office 365 用户帐户列表。

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.ImmutableID -eq $Null} | FT UserPrincipalName,ImmutableID

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.ImmutableID -eq $Null} | FT UserPrincipalName,ImmutableID

UserPrincipalName                  ImmutableId
-----------------                  -----------
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

显示被视为同步用户的 Office 365 用户帐户列表

在以下示例中,我们希望获取同步用户(与 Active Directory 同步)的 Office 365 用户帐户列表。

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.ImmutableID -ne $Null} | FT UserPrincipalName,ImmutableID

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.ImmutableID -ne $Null} | FT UserPrincipalName,ImmutableID

UserPrincipalName                                            ImmutableId             
-----------------                                            -----------             
[email protected]                                          d5DCyKZ6I0anWTd5N2ocLA==
[email protected]                                           2e6Vj6A0xkqP4kmGoFFnuQ==
[email protected]                                           mywviNP7wU2EuZUcrckpiQ==
[email protected]                                        JTDnaYiJhUCyxWWg2ipcBg==
[email protected]                                         9I0cw+JtL0WvT03I+0U6FQ==
[email protected]                                           y5N8BdsrLEmOmxM2emS2Zg==
[email protected]                                           Z5VGE63F50+xYixDHkvX1w==

“已同步用户”的同步时间信息

在本节中,我想简要回顾一下 PowerShell 查询的示例,我们可以使用它来查找有关在特定时间范围内实施的“同步过程”的信息。

显示过去 X 小时内同步的 Office 365 同步用户列表

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.LastDirSyncTime -ge ((Get-Date).AddHours(-10))} | Select UserPrincipalName,WhenCreated, LastDirSyncTime

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.LastDirSyncTime -ge ((Get-Date).AddHours(-10))} | Select UserPrincipalName,WhenCreated, LastDirSyncTime

UserPrincipalName   WhenCreated           LastDirSyncTime      
-----------------   -----------           ---------------      
[email protected] 10/25/2016 7:44:17 PM 12/22/2016 5:13:47 AM

显示过去 X 小时内未同步的 Office 365 同步用户列表

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.LastDirSyncTime -ne ((Get-Date).AddHours(-10))} | Select UserPrincipalName,WhenCreated,LastDirSyncTime

PowerShell 控制台输出示例:

PS C:\> Get-MsolUser | Where-Object {$_.LastDirSyncTime -ne ((Get-Date).AddHours(-10))} | Select UserPrincipalName,WhenCreated,LastDirSyncTime

UserPrincipalName                                               WhenCreated            LastDirSyncTime       
-----------------                                               -----------            ---------------       
[email protected]                                               12/13/2016 11:22:17 AM                       
[email protected]                                           04/14/2016 6:39:46 AM                        
[email protected]                                             09/24/2016 5:28:58 PM  09/25/2016 5:30:26 AM 
[email protected]                                              09/12/2016 6:01:09 AM                        
[email protected]                                        11/28/2016 1:30:42 PM                        
[email protected]                                              10/23/2016 8:58:41 PM  10/23/2016 8:58:41 PM 
[email protected]                                              10/22/2016 3:31:34 AM  10/22/2016 3:31:33 AM 
[email protected]                                            10/16/2016 3:53:48 AM  12/11/2016 12:08:20 PM
[email protected]                                              10/25/2016 7:38:53 PM  11/27/2016 12:17:19 PM

目录同步和错误

在目录同步环境中,由于用户配置设置无效,很有可能会创建目录同步错误。

PowerShell命令语法:

Get-MsolUser | Where-Object {$_.DirSyncProvisioningErrors -eq $True} | FT UserPrincipalName,LastDirSyncTime,WhenCreated,DirSyncProvisioningErrors

我们可以用于“获取”与目录同步环境相关的错误的其他 PowerShell 命令是:

Get-MsolDirSyncProvisioningError

在下一篇文章中,我们将研究使用 PowerShell 查看 Exchange Online 对象。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯