如何将用户名从 Get-MoveRequest 管道传输到 Get-MailboxStatistics?

发布于 2024-12-04 18:37:15 字数 8206 浏览 1 评论 0原文

如何通过管道传输 Exchange 2010 的 Get-MoveRequest 命令的输出,以便可以在下面的 $Username 变量中使用 Name 变量?

[CmdletBinding(DefaultParameterSetName = "MoveUser")]
param(
    [Parameter(Mandatory = $true, ParameterSetName = "MoveUser", ValueFromPipeline = $true, Position = 0)]
    $Username
)

function Get-MBStats($Username  )
{

$req = Get-MailboxStatistics -Identity $Username -IncludeMoveHistory

$UserDetail = ($req).MoveHistory[0] 
 # TODO: SOME CUSTOM STUFF HERE #

New-Object PSObject -Property @{
Username = $Username
Status = $UserDetail.Status
TargetDatabase = $UserDetail.TargetDatabase 
CompletionTime = $UserDetail.CompletionTimestamp
MailboxSizeKB = $UserDetail.TotalMailboxSize.ToKB()
DurationSec = $UserDetail.TotalInProgressDuration.TotalSeconds 
BadItems = $UserDetail.BadItemsEncountered 
}


# Todo: GUI http://msdn.microsoft.com/en-us/magazine/hh288074.aspx #
}

Get-MBStats($Username)

更新

这是 MoveRequest 的成员输出(源)

   TypeName: Microsoft.Exchange.Management.RecipientTasks.MoveRequest

Name                       MemberType   Definition
----                       ----------   ----------
Clone                      Method       System.Object Clone()
Equals                     Method       bool Equals(System.Object obj)
GetHashCode                Method       int GetHashCode()
GetProperties              Method       System.Object[] GetProperties(System.Collections.Generic.ICollection[Microso...
GetType                    Method       type GetType()
ToString                   Method       string ToString()
Validate                   Method       Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName             NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId                 NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
Alias                      Property     System.String Alias {get;set;}
BatchName                  Property     System.String BatchName {get;}
Direction                  Property     Microsoft.Exchange.MailboxReplicationService.RequestDirection Direction {get;}
DisplayName                Property     System.String DisplayName {get;set;}
DistinguishedName          Property     System.String DistinguishedName {get;}
ExchangeGuid               Property     System.Guid ExchangeGuid {get;}
ExchangeVersion            Property     Microsoft.Exchange.Data.ExchangeObjectVersion ExchangeVersion {get;}
ExternalDirectoryObjectId  Property     System.String ExternalDirectoryObjectId {get;}
Flags                      Property     Microsoft.Exchange.Data.Directory.Recipient.RequestFlags Flags {get;}
Guid                       Property     System.Guid Guid {get;}
Identity                   Property     Microsoft.Exchange.Data.ObjectId Identity {get;}
IsOffline                  Property     System.Boolean IsOffline {get;}
IsValid                    Property     System.Boolean IsValid {get;}
LastExchangeChangedTime    Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutr...
Name                       Property     System.String Name {get;set;}
OrganizationId             Property     Microsoft.Exchange.Data.Directory.OrganizationId OrganizationId {get;}
OriginatingServer          Property     System.String OriginatingServer {get;}
Protect                    Property     System.Boolean Protect {get;}
RecipientType              Property     Microsoft.Exchange.Data.Directory.Recipient.RecipientType RecipientType {get;}
RecipientTypeDetails       Property     Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails RecipientTy...
RemoteHostName             Property     System.String RemoteHostName {get;}
RequestStyle               Property     Microsoft.Exchange.MailboxReplicationService.RequestStyle RequestStyle {get;}
SourceArchiveDatabase      Property     Microsoft.Exchange.Data.Directory.ADObjectId SourceArchiveDatabase {get;}
SourceDatabase             Property     Microsoft.Exchange.Data.Directory.ADObjectId SourceDatabase {get;}
Status                     Property     Microsoft.Exchange.Data.Directory.Recipient.RequestStatus Status {get;}
Suspend                    Property     System.Boolean Suspend {get;}
SuspendWhenReadyToComplete Property     System.Boolean SuspendWhenReadyToComplete {get;}
TargetArchiveDatabase      Property     Microsoft.Exchange.Data.Directory.ADObjectId TargetArchiveDatabase {get;}
TargetDatabase             Property     Microsoft.Exchange.Data.Directory.ADObjectId TargetDatabase {get;}

这是目标的成员

   TypeName: Microsoft.Exchange.Data.Mapi.MailboxStatistics

Name                    MemberType   Definition
----                    ----------   ----------
Clone                   Method       System.Object Clone()
Dispose                 Method       System.Void Dispose()
Equals                  Method       bool Equals(System.Object obj)
GetDisposeTracker       Method       Microsoft.Exchange.Diagnostics.DisposeTracker GetDisposeTracker()
GetHashCode             Method       int GetHashCode()
GetProperties           Method       System.Object[] GetProperties(System.Collections.Generic.ICollection[Microsoft....
GetType                 Method       type GetType()
SuppressDisposeTracker  Method       System.Void SuppressDisposeTracker()
ToString                Method       string ToString()
Validate                Method       Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName          NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId              NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
AssociatedItemCount     Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
Database                Property     Microsoft.Exchange.Data.ObjectId Database {get;}
DatabaseName            Property     System.String DatabaseName {get;}
DeletedItemCount        Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
DisconnectDate          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
DisconnectReason        Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.MailboxState, Microsoft.Exchang...
DisplayName             Property     System.String DisplayName {get;}
Identity                Property     Microsoft.Exchange.Data.Mapi.MailboxId Identity {get;}
IsArchiveMailbox        Property     System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, ...
IsQuarantined           Property     System.Boolean IsQuarantined {get;}
IsValid                 Property     System.Boolean IsValid {get;}
ItemCount               Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
LastLoggedOnUserAccount Property     System.String LastLoggedOnUserAccount {get;}
LastLogoffTime          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LastLogonTime           Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LegacyDN                Property     System.String LegacyDN {get;}
MailboxGuid             Property     System.Guid MailboxGuid {get;}
MailboxTableIdentifier  Property     System.String MailboxTableIdentifier {get;}
MapiIdentity            Property     Microsoft.Exchange.Data.Mapi.MapiObjectId MapiIdentity {get;}
MoveHistory             Property     System.Object MoveHistory {get;}
ObjectClass             Property     Microsoft.Exchange.Data.Mapi.ObjectClass ObjectClass {get;}
OriginatingServer       Property     Microsoft.Exchange.Data.Fqdn OriginatingServer {get;}
ServerName              Property     System.String ServerName {get;}
StorageLimitStatus      Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.StorageLimitStatus, Microsoft.E...
TotalDeletedItemSize    Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...
TotalItemSize           Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...

How do I pipeline the output of Exchange 2010's Get-MoveRequest command so that the Name variable can be used in the $Username variable below?

[CmdletBinding(DefaultParameterSetName = "MoveUser")]
param(
    [Parameter(Mandatory = $true, ParameterSetName = "MoveUser", ValueFromPipeline = $true, Position = 0)]
    $Username
)

function Get-MBStats($Username  )
{

$req = Get-MailboxStatistics -Identity $Username -IncludeMoveHistory

$UserDetail = ($req).MoveHistory[0] 
 # TODO: SOME CUSTOM STUFF HERE #

New-Object PSObject -Property @{
Username = $Username
Status = $UserDetail.Status
TargetDatabase = $UserDetail.TargetDatabase 
CompletionTime = $UserDetail.CompletionTimestamp
MailboxSizeKB = $UserDetail.TotalMailboxSize.ToKB()
DurationSec = $UserDetail.TotalInProgressDuration.TotalSeconds 
BadItems = $UserDetail.BadItemsEncountered 
}


# Todo: GUI http://msdn.microsoft.com/en-us/magazine/hh288074.aspx #
}

Get-MBStats($Username)

UPDATE

Here are the members output from MoveRequest (source)

   TypeName: Microsoft.Exchange.Management.RecipientTasks.MoveRequest

Name                       MemberType   Definition
----                       ----------   ----------
Clone                      Method       System.Object Clone()
Equals                     Method       bool Equals(System.Object obj)
GetHashCode                Method       int GetHashCode()
GetProperties              Method       System.Object[] GetProperties(System.Collections.Generic.ICollection[Microso...
GetType                    Method       type GetType()
ToString                   Method       string ToString()
Validate                   Method       Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName             NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId                 NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
Alias                      Property     System.String Alias {get;set;}
BatchName                  Property     System.String BatchName {get;}
Direction                  Property     Microsoft.Exchange.MailboxReplicationService.RequestDirection Direction {get;}
DisplayName                Property     System.String DisplayName {get;set;}
DistinguishedName          Property     System.String DistinguishedName {get;}
ExchangeGuid               Property     System.Guid ExchangeGuid {get;}
ExchangeVersion            Property     Microsoft.Exchange.Data.ExchangeObjectVersion ExchangeVersion {get;}
ExternalDirectoryObjectId  Property     System.String ExternalDirectoryObjectId {get;}
Flags                      Property     Microsoft.Exchange.Data.Directory.Recipient.RequestFlags Flags {get;}
Guid                       Property     System.Guid Guid {get;}
Identity                   Property     Microsoft.Exchange.Data.ObjectId Identity {get;}
IsOffline                  Property     System.Boolean IsOffline {get;}
IsValid                    Property     System.Boolean IsValid {get;}
LastExchangeChangedTime    Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutr...
Name                       Property     System.String Name {get;set;}
OrganizationId             Property     Microsoft.Exchange.Data.Directory.OrganizationId OrganizationId {get;}
OriginatingServer          Property     System.String OriginatingServer {get;}
Protect                    Property     System.Boolean Protect {get;}
RecipientType              Property     Microsoft.Exchange.Data.Directory.Recipient.RecipientType RecipientType {get;}
RecipientTypeDetails       Property     Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails RecipientTy...
RemoteHostName             Property     System.String RemoteHostName {get;}
RequestStyle               Property     Microsoft.Exchange.MailboxReplicationService.RequestStyle RequestStyle {get;}
SourceArchiveDatabase      Property     Microsoft.Exchange.Data.Directory.ADObjectId SourceArchiveDatabase {get;}
SourceDatabase             Property     Microsoft.Exchange.Data.Directory.ADObjectId SourceDatabase {get;}
Status                     Property     Microsoft.Exchange.Data.Directory.Recipient.RequestStatus Status {get;}
Suspend                    Property     System.Boolean Suspend {get;}
SuspendWhenReadyToComplete Property     System.Boolean SuspendWhenReadyToComplete {get;}
TargetArchiveDatabase      Property     Microsoft.Exchange.Data.Directory.ADObjectId TargetArchiveDatabase {get;}
TargetDatabase             Property     Microsoft.Exchange.Data.Directory.ADObjectId TargetDatabase {get;}

Here are the members of the target

   TypeName: Microsoft.Exchange.Data.Mapi.MailboxStatistics

Name                    MemberType   Definition
----                    ----------   ----------
Clone                   Method       System.Object Clone()
Dispose                 Method       System.Void Dispose()
Equals                  Method       bool Equals(System.Object obj)
GetDisposeTracker       Method       Microsoft.Exchange.Diagnostics.DisposeTracker GetDisposeTracker()
GetHashCode             Method       int GetHashCode()
GetProperties           Method       System.Object[] GetProperties(System.Collections.Generic.ICollection[Microsoft....
GetType                 Method       type GetType()
SuppressDisposeTracker  Method       System.Void SuppressDisposeTracker()
ToString                Method       string ToString()
Validate                Method       Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName          NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId              NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
AssociatedItemCount     Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
Database                Property     Microsoft.Exchange.Data.ObjectId Database {get;}
DatabaseName            Property     System.String DatabaseName {get;}
DeletedItemCount        Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
DisconnectDate          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
DisconnectReason        Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.MailboxState, Microsoft.Exchang...
DisplayName             Property     System.String DisplayName {get;}
Identity                Property     Microsoft.Exchange.Data.Mapi.MailboxId Identity {get;}
IsArchiveMailbox        Property     System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, ...
IsQuarantined           Property     System.Boolean IsQuarantined {get;}
IsValid                 Property     System.Boolean IsValid {get;}
ItemCount               Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
LastLoggedOnUserAccount Property     System.String LastLoggedOnUserAccount {get;}
LastLogoffTime          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LastLogonTime           Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LegacyDN                Property     System.String LegacyDN {get;}
MailboxGuid             Property     System.Guid MailboxGuid {get;}
MailboxTableIdentifier  Property     System.String MailboxTableIdentifier {get;}
MapiIdentity            Property     Microsoft.Exchange.Data.Mapi.MapiObjectId MapiIdentity {get;}
MoveHistory             Property     System.Object MoveHistory {get;}
ObjectClass             Property     Microsoft.Exchange.Data.Mapi.ObjectClass ObjectClass {get;}
OriginatingServer       Property     Microsoft.Exchange.Data.Fqdn OriginatingServer {get;}
ServerName              Property     System.String ServerName {get;}
StorageLimitStatus      Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.StorageLimitStatus, Microsoft.E...
TotalDeletedItemSize    Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...
TotalItemSize           Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2024-12-11 18:37:15

文档并不清楚 Get-MoveRequest 返回什么,但您可以尝试如下所示:

Get-MoveRequest ... | select -expand Name | Get-MBStats

The documentation is not clear on what Get-MoveRequest returns, but something like below is what you can try:

Get-MoveRequest ... | select -expand Name | Get-MBStats
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文