Я запускаю приведенный ниже скрипт из Remoting (Ноутбук с PowerShell ISE на локальный Exchange), чтобы получить размер почтового ящика и разрешения, затем экспортировать в файл .CSV:
$DataPath = "C:\mbxresults.csv"
$UserMailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ObjectClass -notmatch '(SystemAttendantMailbox|ExOleDbSystemMailbox)' -and $_.RecipientTypeDetails -ne "DiscoveryMailbox" }
ForEach ($mailboxes in $UserMailboxes) {
$UPN = $mailboxes.UserPrincipalName
$MailboxPermission = Get-MailboxPermission -Identity $UPN | Where-Object {("$($_.AccessRights)".Split(', ') -contains 'FullAccess') -and (-not $_.IsInherited) -and ($_.User.toString() -ne "NT AUTHORITY\SELF") -and ($_.User.toString() -notlike '*Discovery Management*')}
$MailboxStats = Get-MailboxStatistics -Identity $UPN
$User = Get-User -Identity $UPN
[pscustomobject]([ordered]@{
Name = $mailboxes.Name
PrimarySmtpAddress = $_.PrimarySmtpAddress
UPN = $UPN
Alias = $mailboxes.alias
OU = $mailboxes.organizationalUnit
Server = $MailboxStats.ServerName
Database = $MailboxStats.DatabaseName
TotaItemSize = [Math]::Round([Int64]($MailboxStats).TotalItemSize.Value.ToString().Split("(")[1].Split()[0].Replace(",","") / 1MB, 2)
Notes = $User.Notes
RecipientTypeDetails = $_.RecipientTypeDetails.ToString()
FullAccess = ($MailboxPermission | ForEach-Object {$_.User.ToString()}) -join ', '
})
} | Sort-Object -Property TotaItemSize | Export-Csv -NoTypeInformation -Path $DataPath
Но как-тоэто не правильно?
См. ниже ошибку:
At C:\Temp\Get-PermissionANDSize.ps1:22 char:3
+ } | Sort-Object -Property TotaItemSize | Export-Csv -NoTypeInformatio ...
+ ~
An empty pipe element is not allowed.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : EmptyPipeElement
You cannot call a method on a null-valued expression.
At line:9 char:2
+ [pscustomobject]([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:9 char:2
+ [pscustomobject]([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:9 char:2
+ [pscustomobject]([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Как я могу исправить проблему?