How get todays month value in powershell?


Microsoft PowerShell

Microsoft Windows 2019 Server


How get the month value from datetime function in powershell?


Enter a ps1 script like this:

# get today's day number: Get-Date -UFormat "%d"
# set month value in a variable: [String]$Manaden = (Get-Date -UFormat "%m")

[String]$Dagen = (Get-Date -UFormat "%d")
[String]$Manaden = (Get-Date -UFormat "%m")

# debug lines 
Write-Host [$Manaden]


UFormat specifiers to format the DateTime result of Get-Date in PowerShell. Return a formatted string and not a date object.


More information:

Get-Date – How to get and use Dates in PowerShell