user2307236
user2307236

Reputation: 755

Powershell truncated output

I am currently running a simple script which is intended to retrieve all the mailboxes a user has access to. My problem is that the first column (Identity) is being truncated and hence I cannot see the mailbox name. I tried various options such as -AutoSize, changing the $FormatEnumerationLimit =-1 to no avail.

Script:-

$FormatEnumerationLimit =-1
Add-PSSnapin *Microsoft.Exchange*
Get-Mailbox | Get-MailboxPermission -User username | Out-File C:\temp\test.txt

Result:-

Identity         User            AccessRights      IsInherited  Deny
---------        ----            ------------      -----------  ----

domain/Mai...    DOMAIN\username {FullAccess}       False       False

Upvotes: 0

Views: 3933

Answers (3)

filimonic
filimonic

Reputation: 4634

... | Out-GridView <# Works only in Powershell ISE #>

Gives you Excel-like data grid wih basic search and filters. Can be CTRL+A, CTRL+C copied to Excel (without headers). Works only in Powershell ISE


... | Export-Csv -LiteralPath 'c:\File.csv' -Encoding UTF32 -Delimiter "`t" -NoTypeInformation

Gives you CSV file that is easily opened by Excel ( the magic of UTF32 and "`t" delimeters ). No need to make "Text to columns"


... | Format-Table -Autosize 

gives you a table


... | Format-List

gives you multiline output


... | Select @( 'User', 'AccessRights', '*count*' ) | ...

Gives you ability to select only fields you need ( this is typed immediately before output function like Get-Mailbox | Select @('User', 'AccessRights') | Out-GridView


... | Foreach-Object {
    $local:color = 'Green'
    if ( -not $_.Enabled) { $local:color = 'Yellow' }
    Write-Host "Username: $($_.samaccountname)" -f $local:color
    Write-Host "Enabled: $($_.Enabled)" -f $local:color
    ...
}

Your own scriptblock gives you output freedom ;)

Upvotes: 1

P V Ajay Thota
P V Ajay Thota

Reputation: 103

Instead you can use the command below if you want to see the information only on console

Get-Mailbox | Get-MailboxPermission -User username | format-list

or collect the output to a csv file

Get-Mailbox | Get-MailboxPermission -User username | export-csv c:\test.csv -notype -force

Upvotes: 2

Vinod kumar G
Vinod kumar G

Reputation: 655

Just for your reference, select the needed column using select query and pipe it the out-file/export-csv values and out to csv/txt file.

Get-Process | select id,ProcessName | Format-Table | Out-File -FilePath C:\Users\vinod\De
sktop\AI\process.csv

Upvotes: 1

Related Questions