Solved

PowerShell command / script to get previous month

Posted on 2014-04-10
2
3,492 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article will help you understand what HashTables are and how to use them in PowerShell.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

785 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