Calculating with PowerShell

PowerShell supports all possible types of calculations. The following examples will help you explore the possibilities of PowerShell.

Simple calculation

8 * 8 / 4


(4+4) / 2


Calculating with KB, MB, GB and TB to PB


How many 150 MB files fit on a 64GB USB drive?


How old am I?

I have to admit: This does not necessarily have to do with classical calculation as in the examples above, but is quite cool.

(Get-Date) - (Get-Date -Year 1976 -Month 03 -Day 21)


What day of week was I born?

(Get-Date -Year 1976 -Month 03 -Day 21).dayofweek


.dayofweek is an attribute and can be retrieved using a point.

Which users have not logged on to the domain for 1 year?

Get-ADUser -Filter * -Properties LastLogonDate | ? {$_.lastlogondate -ne $null -and $_.lastlogondate -le ((get-date).adddays(-365))} | Format-List Name,LastLogonDate

.adddays is a method. First, we retreive the actual date with Get-Date. Then the method adddays calculates 365 days back.

Which users have not logged on to their Mailbox (Exchange) for 1 year?

Get-MailboxStatistics -server server01 | ? {$_.lastlogontime -ne $null -and $_.lastlogontime -le ((get-date).adddays(-365))} | Sort-Object {$_.lastlogontime}


Have fun computing in PowerShell!

Categories: PowerShell

Tagged as: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.