Home » PowerShell » Calculating with PowerShell

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!

Leave a Reply

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

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s



My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on