Reputation: 340
I have this snippet of code that converts a registry value to a date string (originally hex value 2f 04 1e 00 00 00 00 00):
ElseIf (($sepmastersvc)) {
$sepmasterst = [bool]$sepmaster
$sepStatus = $sepmastersvc.status
$SEPVscan = (get-itemproperty "HKLM:SOFTWARE\Wow6432Node\Symantec\Symantec Endpoint Protection\AV") 2> $null
If (!($SEPVscan)) {
$SEPVscanStatus = [bool]$SEPVscan
$SEPDatVer = "N/A"
}
Else {
$SEPVscanStatus = [bool]$SEPVscan
$SEPDatVerY = [string]($SEPVscan.PatternFileDate[0] + 1970)
$SEPDatVerM = ($DateTimeFormat.MonthNames[$SEPVscan.PatternFileDate[1]])
$SEPDatD = [string]$SEPVscan.PatternFileDate[2]
$SEPDatVer = $SEPDatVerY + $SEPDatVerM + $SEPDatD
}
}
I need to get the month number instead of name.
I've found examples of converting a month number to name but can't get it working the other way around.
Upvotes: 0
Views: 6499
Reputation: 9991
You can use Get-Date and specify the format. "MM" will retrieve the month in 2 digit number.
get-date -format "MM"
Here is a list of possible formats: https://technet.microsoft.com/en-us/library/ee692801.aspx
I'm not sure what format your date is, but from what I can see, you could try
Get-Date -Date "$SEPDatVerM $SEPDatD $SEPDatVerY" -format "yyyy MM dd"
and that should give you a date formatted as this: for example "2015 03 21"
Upvotes: 3