Hello,<\/p>\n
First off my powershell capability is very low so I am struggling with this. If anyone can help I would greatly appreciate it.<\/p>\n
I am trying to run a small commnd / script to get the following in a CSV for sorting:<\/p>\n
Displayname<\/p>\n
PrimarySMTPAddress<\/p>\n
Department<\/p>\n
TotalitemSize<\/p>\n
I have tried a few things I have fround on teh net but cant seem to either get it to output what I want or it breaks altogether. This is the best I could come up with but it isn’t outputting everything I need:<\/p>\n
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,TotalItemSize, @{Name=“Department”;expression={(get-user $_.alias).department}}<\/p>\n
Any help is appreciated.<\/p>","upvoteCount":7,"answerCount":7,"datePublished":"2018-01-25T11:39:46.000Z","author":{"@type":"Person","name":"psycholiquid","url":"https://community.spiceworks.com/u/psycholiquid"},"acceptedAnswer":{"@type":"Answer","text":"
try this<\/p>\n
$outtbl = @()\n$users = Get-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’}\n$users | % {\n $x = Get-MailboxStatistics $_ |select TotalItemSize\n $t = New-Object PSObject -Property @{\n Name = $_.Name\n TotalItemSize = $x.TotalItemSize\n Department=$_.Department\n Email=$_.WindowsEmailAddress\n }\n $outtbl += $t\n}\n$outtbl | Export-Csv c:\\ussersxx.csv -NoTypeInformation\n\n## To get only enabled acounts\n\nGet-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’ -and $_.useraccountcontrol -notlike '*accountdisabled*'}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2018-01-25T12:52:37.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/4","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello,<\/p>\n
First off my powershell capability is very low so I am struggling with this. If anyone can help I would greatly appreciate it.<\/p>\n
I am trying to run a small commnd / script to get the following in a CSV for sorting:<\/p>\n
Displayname<\/p>\n
PrimarySMTPAddress<\/p>\n
Department<\/p>\n
TotalitemSize<\/p>\n
I have tried a few things I have fround on teh net but cant seem to either get it to output what I want or it breaks altogether. This is the best I could come up with but it isn’t outputting everything I need:<\/p>\n
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,TotalItemSize, @{Name=“Department”;expression={(get-user $_.alias).department}}<\/p>\n
Any help is appreciated.<\/p>","upvoteCount":7,"datePublished":"2018-01-25T11:39:46.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/1","author":{"@type":"Person","name":"psycholiquid","url":"https://community.spiceworks.com/u/psycholiquid"}},{"@type":"Answer","text":"
To get the mailbox size details, you’ll need to use the Get-MailboxStatistics cmdlet as well.<\/p>","upvoteCount":0,"datePublished":"2018-01-25T12:13:00.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/2","author":{"@type":"Person","name":"dmc1981","url":"https://community.spiceworks.com/u/dmc1981"}},{"@type":"Answer","text":"
Where are you getting the user information from?<\/p>","upvoteCount":0,"datePublished":"2018-01-25T12:46:42.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/3","author":{"@type":"Person","name":"Phil-Adler","url":"https://community.spiceworks.com/u/Phil-Adler"}},{"@type":"Answer","text":"\n\n
<\/div>\n 1981DMC:<\/div>\n
\nTo get the mailbox size details, you’ll need to use the Get-MailboxStatistics cmdlet as well.<\/p>\n<\/blockquote>\n<\/aside>\n
Here’s another approach. I created a data table object and cast the 4 criteria you requested into each column and corresponding row. If the AD “EmailAddress” property doesn’t suffice for primary SMTP address, you could just call the “get-mailbox” cmdlet in place of pulling that data from the get-aduser cmdlet.<\/p>\n
$newTable=New-Object System.Data.DataTable \"Info\"\n\n$col0=New-Object System.Data.DataColumn DisplayName,([string])\n$col1=New-Object System.Data.DataColumn PrimarySMTPAddress,([string])\n$col2=New-Object System.Data.DataColumn Department,([string])\n$col3=New-Object System.Data.DataColumn TotalItemSize,([string])\n\n$newTable.Columns.AddRange(@($col0,$col1,$col2,$col3))\n\n$users=Get-AdUser -Properties Department,EmailAddress,DisplayName -Filter * -SearchBase \"ou=parentcontainer,dc=domain,dc=com\"\n\nforeach ($user in $users)\n{\n $row0=$newTable.NewRow()\n $row0.DisplayName=$user.DisplayName\n $row0.PrimarySMTPAddress=$user.EmailAddress\n $row0.Department=$user.Department\n $row0.TotalItemSize=(Get-MailboxStatistics -id $user.samaccountname).TotalItemSize.value\n $newTable.Rows.Add($row0)\n}\n\n$newTable | sort DisplayName | ft -AutoSize\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2018-01-25T12:56:23.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/5","author":{"@type":"Person","name":"dmc1981","url":"https://community.spiceworks.com/u/dmc1981"}},{"@type":"Answer","text":"Thank you I will try these out after my meetings<\/p>","upvoteCount":0,"datePublished":"2018-01-25T13:28:54.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/6","author":{"@type":"Person","name":"psycholiquid","url":"https://community.spiceworks.com/u/psycholiquid"}},{"@type":"Answer","text":"\n\n
<\/div>\n
JitenSh:<\/div>\n
\ntry this<\/p>\n
$outtbl = @()\n$users = Get-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’}\n$users | % {\n $x = Get-MailboxStatistics $_ |select TotalItemSize\n $t = New-Object PSObject -Property @{\n Name = $_.Name\n TotalItemSize = $x.TotalItemSize\n Department=$_.Department\n Email=$_.WindowsEmailAddress\n }\n $outtbl += $t\n}\n$outtbl | Export-Csv c:\\ussersxx.csv -NoTypeInformation\n\n## To get only enabled acounts\n\nGet-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’ -and $_.useraccountcontrol -notlike '*accountdisabled*'}\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nBoth answers worked like champs and thank you both for writing that for me. I wish I could choose more than one best answers in this case, but it would only let me chose one.<\/p>","upvoteCount":0,"datePublished":"2018-01-25T14:35:13.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell-script/630845/7","author":{"@type":"Person","name":"psycholiquid","url":"https://community.spiceworks.com/u/psycholiquid"}}]}}
Hello,
First off my powershell capability is very low so I am struggling with this. If anyone can help I would greatly appreciate it.
I am trying to run a small commnd / script to get the following in a CSV for sorting:
Displayname
PrimarySMTPAddress
Department
TotalitemSize
I have tried a few things I have fround on teh net but cant seem to either get it to output what I want or it breaks altogether. This is the best I could come up with but it isn’t outputting everything I need:
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,TotalItemSize, @{Name=“Department”;expression={(get-user $_.alias).department}}
Any help is appreciated.
7 Spice ups
dmc1981
(DMC1981)
January 25, 2018, 12:13pm
2
To get the mailbox size details, you’ll need to use the Get-MailboxStatistics cmdlet as well.
Phil-Adler
(Phil Adler)
January 25, 2018, 12:46pm
3
Where are you getting the user information from?
jitensh
(JitenSh)
January 25, 2018, 12:52pm
4
try this
$outtbl = @()
$users = Get-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’}
$users | % {
$x = Get-MailboxStatistics $_ |select TotalItemSize
$t = New-Object PSObject -Property @{
Name = $_.Name
TotalItemSize = $x.TotalItemSize
Department=$_.Department
Email=$_.WindowsEmailAddress
}
$outtbl += $t
}
$outtbl | Export-Csv c:\ussersxx.csv -NoTypeInformation
## To get only enabled acounts
Get-User -ResultSize Unlimited | Where { $_.RecipientType -eq ‘UserMailbox’ -and $_.useraccountcontrol -notlike '*accountdisabled*'}
2 Spice ups
dmc1981
(DMC1981)
January 25, 2018, 12:56pm
5
Here’s another approach. I created a data table object and cast the 4 criteria you requested into each column and corresponding row. If the AD “EmailAddress” property doesn’t suffice for primary SMTP address, you could just call the “get-mailbox” cmdlet in place of pulling that data from the get-aduser cmdlet.
$newTable=New-Object System.Data.DataTable "Info"
$col0=New-Object System.Data.DataColumn DisplayName,([string])
$col1=New-Object System.Data.DataColumn PrimarySMTPAddress,([string])
$col2=New-Object System.Data.DataColumn Department,([string])
$col3=New-Object System.Data.DataColumn TotalItemSize,([string])
$newTable.Columns.AddRange(@($col0,$col1,$col2,$col3))
$users=Get-AdUser -Properties Department,EmailAddress,DisplayName -Filter * -SearchBase "ou=parentcontainer,dc=domain,dc=com"
foreach ($user in $users)
{
$row0=$newTable.NewRow()
$row0.DisplayName=$user.DisplayName
$row0.PrimarySMTPAddress=$user.EmailAddress
$row0.Department=$user.Department
$row0.TotalItemSize=(Get-MailboxStatistics -id $user.samaccountname).TotalItemSize.value
$newTable.Rows.Add($row0)
}
$newTable | sort DisplayName | ft -AutoSize
1 Spice up
Thank you I will try these out after my meetings
Both answers worked like champs and thank you both for writing that for me. I wish I could choose more than one best answers in this case, but it would only let me chose one.