How to Get Current Date While Using PowerShell Script

We all might have faced a scenario where we need to get the current date in our process while running the PowerShell script.
 
It's easy  just use the function Get-Date  and store it in a variable. This will populate the current date for your script.
 
To use this code in SharePoint you need to have it in correct format. So what is the date format for the SharePoint Fields?

It is SortableDateTimePattern (based on ISO 8601) using local time.
 
So when you use the function Get-Date, use it in this format.
 
Example

Get-Date -format s
 
This will generate a date field exactly in SharePoint format which is 2016-05-24T10:20:30.
Ebook Download
View all
Learn
View all