SID-500

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

1.PNG

(4+4) / 2

2.PNG

Calculating with KB, MB, GB and TB to PB

3.PNG

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

4.PNG

How old am i?

I admit: This does not necessarily have to do with classical calculation as in the examples above, but is quite cool. For this, we need the command Get-Date.

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

5.PNG

What weekday was i born?

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

6.PNG

.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}

Unbenannt.PNG

Have fun computing in PowerShell!


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 )

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

Categories

Who is the blogger?

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 WordPress.com