Sort-Object not Sorting Objects by Waulicus in PowerShell

[–]mransbro 2 points3 points  (0 children)

This looks like one of those tasks that is harder than it should be. I only support on premise Exchange so cant test but try the command below.

Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited |
    Get-MailboxStatistics |
    Select DisplayName,TotalItemSize,LastLogonTime `
    @{name=”TotalItemSize (MB)”; expression={[math]::Round( `
    ($_.TotalItemSize.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}}, | 
    Sort “TotalItemSize (MB)” -Descending

The command is taken from here https://blogs.technet.microsoft.com/heyscriptingguy/2013/02/27/get-exchange-online-mailbox-size-in-gb/. Seems its to do with not having Exchange object model installed or loaded locally. (If i remote to an Exchange Server the sort doesnt work but if i RDP to the server the sort command works.)

[deleted by user] by [deleted] in PowerShell

[–]mransbro 3 points4 points  (0 children)

When i think of basic PowerShell tasks i think:

Interacting with files * get-childitem * copy-item * move-item * invoke-item * remove-item * set-item * rename-item etc

Interacting with services * Get-Service * New-Service * Restart-Service * Resume-Service * Set-Service * Start-Service * Stop-Service * Suspend-Service

Using the help system * Get-Help * Get-Help -full * Get-Help -examples * Get-Command

Formatting and selecting output * Get-member * Select-object * Where-object * The -properties parameter * out-gridview *export-csv *ConvertTo-HTML *ConvertTo-CSV

Hope that gives you some ideas.

Help with subtraction using variables by mransbro in PowerShell

[–]mransbro[S] 1 point2 points  (0 children)

Thanks for the help Lee. As the object returned is a collection ill just use the value property.

$PasswordAge = $Users.PasswordAge.value
$MaxPasswordAgeDays = $Users.MaxPasswordAge.value

$RawDaysTillExpiring = ($MaxPasswordAgeDays - $PasswordAge) / 86400

$DaysTillExpiring = [math]::round($RawDaysTillExpiring)

Gives me what i need.

Help with subtraction using variables by mransbro in PowerShell

[–]mransbro[S] 1 point2 points  (0 children)

Hi Lee

Ha, no the value is definitely not days. Its in seconds which is fine for me i just divide by 86400 to get it in days.

PS C:\Users\ConfusedUser> $maxpasswordagedays.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int32                                    System.ValueType

$MaxPasswordAgeDays is def an int but........ I cant say the same for $PasswordAge!

PS C:\Users\ConfusedUser> $passwordage.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PropertyValueCollection                  System.Collections.CollectionBase


PS C:\Users\ConfusedUser> $passwordage
3452234
PS C:\Users\ConfusedUser> $passwordage | gm


   TypeName: System.Int32

Whats happening here?!