Product:
Microsoft PowerShell
Microsoft Windows 2019 Server
Issue:
How get the month value from datetime function in powershell?
Solution:
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:
https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/