我需要将下面命令中的特定结果传递给我可以在另一个命令中使用的变量。更具体地说,folderpath
领域。是否有捷径可寻?我不熟悉Where-Object
cmdlet。有人能举个例子吗?
Get-MailboxFolderStatistics $user1 -FolderScope Calendar
结果(以及更多):
RunspaceId : dsfdsfsdfsf9
Date : 24/07/2014 8:41:48
CreationTime : 24/07/2014 8:41:48
LastModifiedTime : 5/09/2018 12:42:37
Name : Kalender
FolderPath : /Kalender
FolderId : LgAAAADmF+sdfsdfdf/KAAAAAAENAAAC
FolderType : Calendar
ContentFolder : True
ContentMailboxGuid : 86afb4sfdsfdsdfsd7
$folderPath = Get-MailboxFolderStatistics $user1 -FolderScope Calendar | Select-Object -ExpandProperty FolderPath
您可以使用以下方法之一访问该属性:
(Get-MailboxFolderStatistics $user1 -FolderScope Calendar).FolderPath
# or
Get-MailboxFolderStatistics $user1 -FolderScope Calendar | Select-Object -ExpandProperty FolderPath
要分配给变量,只需添加分配:
$folder = (Get-MailboxFolderStatistics $user1 -FolderScope Calendar).FolderPath
# or
$folder = Get-MailboxFolderStatistics $user1 -FolderScope Calendar | Select-Object -ExpandProperty FolderPath
可能会发生变量将是具有多个对象的数组。然后你可以使用$folder[$i]
访问它们中的任何一个,其中$i
是一个索引(从0开始)。如果您想要更通用的解决方案,可以使用以下命令强制变量为数组:
[array]$folder = (Get-MailboxFolderStatistics $user1 -FolderScope Calendar).FolderPath
# or
[array]$folder = Get-MailboxFolderStatistics $user1 -FolderScope Calendar | Select-Object -ExpandProperty FolderPath