Solved

PowerShell command / script to get previous month

Posted on 2014-04-10
2
2,973 Views
Last Modified: 2014-04-10
Q1:
I could get the current month with the command
below.  How do I get the previous month ie March ?

PS C:\Users\Art> Get-Date -format MMMM
April


Q2:
Likewise, how do I get previous & next day's date?

I'm on Win 2008 R2 and Windows 7 Profsnl : guess
it's the same PowerShell for both
0
Comment
Question by:sunhux
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39991135
With the AddMonths() and AddDays() methods, for example like this:
$Today = Get-Date
$LastMonth = $Today.AddMonths(-1) | Get-Date -Format "MMMM"
$Yesterday = $Today.AddDays(-1)
$Tomorrow = $Today.AddDays(1)

Open in new window

You can pipe any object to Get-Member (or the "gm" alias) to find the methods supported. In this case: Get-Date | gm
0
 

Author Closing Comment

by:sunhux
ID: 39991148
Wonderful
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
This article will help you understand what HashTables are and how to use them in PowerShell.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now