string manipulation for a password



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Good day,



I'm trying to create a default password base of the date that is the user is starting. For example, if the user starts on "11/10/2018", the password should be
"Sep10th2018!"



this is what I have. It "works" but I'm sure there should be a better way to doing this. I just don't know how. Just in case, this is not so much of an issue. Is more for learning sake. I'm trying to be better at PowerShell.



# Generate Default Password
IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "1")
$Month = "Jan"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "2")
$Month = "Feb"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "3")
$Month = "Mar"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "4")
$Month = "Apr"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "5")
$Month = "May"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "6")
$Month = "Jun"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "7")
$Month = "Jul"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "8")
$Month = "Aug"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "9")
$Month = "Sep"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "0")
$Month = "Oct"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "1")
$Month = "Nov"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "2")
$Month = "Dec"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")


[string]$password2 = @($Month + $Day + $Year)
$password = $password2 | ConvertTo-SecureString -AsPlainText -Force
$password









share|improve this question






















  • Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

    – trebleCode
    Nov 15 '18 at 16:07











  • I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

    – Yaboy
    Nov 15 '18 at 16:12


















0















Good day,



I'm trying to create a default password base of the date that is the user is starting. For example, if the user starts on "11/10/2018", the password should be
"Sep10th2018!"



this is what I have. It "works" but I'm sure there should be a better way to doing this. I just don't know how. Just in case, this is not so much of an issue. Is more for learning sake. I'm trying to be better at PowerShell.



# Generate Default Password
IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "1")
$Month = "Jan"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "2")
$Month = "Feb"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "3")
$Month = "Mar"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "4")
$Month = "Apr"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "5")
$Month = "May"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "6")
$Month = "Jun"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "7")
$Month = "Jul"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "8")
$Month = "Aug"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "9")
$Month = "Sep"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "0")
$Month = "Oct"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "1")
$Month = "Nov"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "2")
$Month = "Dec"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")


[string]$password2 = @($Month + $Day + $Year)
$password = $password2 | ConvertTo-SecureString -AsPlainText -Force
$password









share|improve this question






















  • Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

    – trebleCode
    Nov 15 '18 at 16:07











  • I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

    – Yaboy
    Nov 15 '18 at 16:12














0












0








0








Good day,



I'm trying to create a default password base of the date that is the user is starting. For example, if the user starts on "11/10/2018", the password should be
"Sep10th2018!"



this is what I have. It "works" but I'm sure there should be a better way to doing this. I just don't know how. Just in case, this is not so much of an issue. Is more for learning sake. I'm trying to be better at PowerShell.



# Generate Default Password
IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "1")
$Month = "Jan"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "2")
$Month = "Feb"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "3")
$Month = "Mar"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "4")
$Month = "Apr"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "5")
$Month = "May"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "6")
$Month = "Jun"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "7")
$Month = "Jul"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "8")
$Month = "Aug"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "9")
$Month = "Sep"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "0")
$Month = "Oct"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "1")
$Month = "Nov"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "2")
$Month = "Dec"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")


[string]$password2 = @($Month + $Day + $Year)
$password = $password2 | ConvertTo-SecureString -AsPlainText -Force
$password









share|improve this question














Good day,



I'm trying to create a default password base of the date that is the user is starting. For example, if the user starts on "11/10/2018", the password should be
"Sep10th2018!"



this is what I have. It "works" but I'm sure there should be a better way to doing this. I just don't know how. Just in case, this is not so much of an issue. Is more for learning sake. I'm trying to be better at PowerShell.



# Generate Default Password
IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "1")
$Month = "Jan"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "2")
$Month = "Feb"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "3")
$Month = "Mar"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "4")
$Month = "Apr"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "5")
$Month = "May"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "6")
$Month = "Jun"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "7")
$Month = "Jul"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "8")
$Month = "Aug"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "0" -and $StartDate[1] -eq "9")
$Month = "Sep"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "0")
$Month = "Oct"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "1")
$Month = "Nov"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")

IF ($StartDate[0] -eq "1" -and $StartDate[1] -eq "2")
$Month = "Dec"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "1") $Day = "1st"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "2") $Day = "2nd"
IF ($StartDate[3] -eq "0" -eq $StartDate[4] -eq "3") $Day = "3rd"
Else $Day = @($StartDate[3] + $StartDate[4] + "th")
$Year = @("20" + $StartDate[8] + $StartDate[9] + "!")


[string]$password2 = @($Month + $Day + $Year)
$password = $password2 | ConvertTo-SecureString -AsPlainText -Force
$password






powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 16:04









YaboyYaboy

143




143












  • Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

    – trebleCode
    Nov 15 '18 at 16:07











  • I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

    – Yaboy
    Nov 15 '18 at 16:12


















  • Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

    – trebleCode
    Nov 15 '18 at 16:07











  • I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

    – Yaboy
    Nov 15 '18 at 16:12

















Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

– trebleCode
Nov 15 '18 at 16:07





Where are you getting $StartDate from - an AD user property or somewhere else? Knowing this might help with discerning a more elegant solution

– trebleCode
Nov 15 '18 at 16:07













I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

– Yaboy
Nov 15 '18 at 16:12






I put in manually into a variable like; $StartDate = Read-Host "StartDate?"

– Yaboy
Nov 15 '18 at 16:12













3 Answers
3






active

oldest

votes


















1














Using regex to get the day suffix, and format operator to build the password:



function Get-DateSuffix([datetime]$Date) 
switch -regex ($Date.Day.ToString()) 2


[datetime]$StartDate = "11/10/2018"

$password = "0:MMM123!" -f $StartDate, $StartDate.Day, (Get-DateSuffix $StartDate), $StartDate.Year





share|improve this answer




















  • 1





    shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

    – LotPings
    Nov 15 '18 at 19:23


















2














Repurposing the elegant C# solution here, you can do it like this in PowerShell:



 function Get-DaySuffix($day)

switch ($day)

$day -in (1,21,31) "st"
$day -in (2,22) "nd"
$day -in (3,23) "rd"
default "th"



# Change to some other means of getting date - e.g. Read-Host
$startDate = Get-Date "23/05/2007"

# Get a collection of the month names (e.g. Jan, Feb, mar, etc)
$months = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat.AbbreviatedMonthNames

# Build the password from the date parts
$password = "$($months[$startDate.Month-1])$($startDate.Day)$(Get-DaySuffix $startDate.Day)$($startDate.Year)!"


In this case $password is set to May23rd2007!.






share|improve this answer






























    2














    Disclaimer: you probably already know, but I have to state that that's a very bad password, if you can even call it that




    Most of this can be offloaded to the DateTime type, all except for the ordinal suffixes for the day of the month.



    I would break it down into 3 steps:



    1. Parse input date

    2. Generate first half

    3. Calculate the suffix

    4. Append the year


    # Parse the input date
    $inputDate = Read-Host "Input date in the format MM/dd/yyyy"
    $date = [datetime]::ParseExact($inputDate,'MM/dd/yyyy',$null)

    # Generate first half
    $dateString = $date.ToString('MMMdd')

    # Calculate the ordinal suffix
    $day = $date.Day
    if($day -in 1,21,31)
    $dateString += 'st'

    else if($day -in 2,22)
    $dateString += 'nd'

    else if($day -in 3,23)
    $dateString += 'rd'

    else
    $dateString += 'th'


    # Append the year:
    $dateString += $date.ToString('yyyy!')





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323403%2fstring-manipulation-for-a-password%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Using regex to get the day suffix, and format operator to build the password:



      function Get-DateSuffix([datetime]$Date) 
      switch -regex ($Date.Day.ToString()) 2


      [datetime]$StartDate = "11/10/2018"

      $password = "0:MMM123!" -f $StartDate, $StartDate.Day, (Get-DateSuffix $StartDate), $StartDate.Year





      share|improve this answer




















      • 1





        shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

        – LotPings
        Nov 15 '18 at 19:23















      1














      Using regex to get the day suffix, and format operator to build the password:



      function Get-DateSuffix([datetime]$Date) 
      switch -regex ($Date.Day.ToString()) 2


      [datetime]$StartDate = "11/10/2018"

      $password = "0:MMM123!" -f $StartDate, $StartDate.Day, (Get-DateSuffix $StartDate), $StartDate.Year





      share|improve this answer




















      • 1





        shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

        – LotPings
        Nov 15 '18 at 19:23













      1












      1








      1







      Using regex to get the day suffix, and format operator to build the password:



      function Get-DateSuffix([datetime]$Date) 
      switch -regex ($Date.Day.ToString()) 2


      [datetime]$StartDate = "11/10/2018"

      $password = "0:MMM123!" -f $StartDate, $StartDate.Day, (Get-DateSuffix $StartDate), $StartDate.Year





      share|improve this answer















      Using regex to get the day suffix, and format operator to build the password:



      function Get-DateSuffix([datetime]$Date) 
      switch -regex ($Date.Day.ToString()) 2


      [datetime]$StartDate = "11/10/2018"

      $password = "0:MMM123!" -f $StartDate, $StartDate.Day, (Get-DateSuffix $StartDate), $StartDate.Year






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 16 '18 at 10:37

























      answered Nov 15 '18 at 16:42









      James C.James C.

      9,13122233




      9,13122233







      • 1





        shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

        – LotPings
        Nov 15 '18 at 19:23












      • 1





        shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

        – LotPings
        Nov 15 '18 at 19:23







      1




      1





      shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

      – LotPings
      Nov 15 '18 at 19:23





      shouldn't '1(1|2|3)$' 'th' have a break to avoid an array?

      – LotPings
      Nov 15 '18 at 19:23













      2














      Repurposing the elegant C# solution here, you can do it like this in PowerShell:



       function Get-DaySuffix($day)

      switch ($day)

      $day -in (1,21,31) "st"
      $day -in (2,22) "nd"
      $day -in (3,23) "rd"
      default "th"



      # Change to some other means of getting date - e.g. Read-Host
      $startDate = Get-Date "23/05/2007"

      # Get a collection of the month names (e.g. Jan, Feb, mar, etc)
      $months = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat.AbbreviatedMonthNames

      # Build the password from the date parts
      $password = "$($months[$startDate.Month-1])$($startDate.Day)$(Get-DaySuffix $startDate.Day)$($startDate.Year)!"


      In this case $password is set to May23rd2007!.






      share|improve this answer



























        2














        Repurposing the elegant C# solution here, you can do it like this in PowerShell:



         function Get-DaySuffix($day)

        switch ($day)

        $day -in (1,21,31) "st"
        $day -in (2,22) "nd"
        $day -in (3,23) "rd"
        default "th"



        # Change to some other means of getting date - e.g. Read-Host
        $startDate = Get-Date "23/05/2007"

        # Get a collection of the month names (e.g. Jan, Feb, mar, etc)
        $months = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat.AbbreviatedMonthNames

        # Build the password from the date parts
        $password = "$($months[$startDate.Month-1])$($startDate.Day)$(Get-DaySuffix $startDate.Day)$($startDate.Year)!"


        In this case $password is set to May23rd2007!.






        share|improve this answer

























          2












          2








          2







          Repurposing the elegant C# solution here, you can do it like this in PowerShell:



           function Get-DaySuffix($day)

          switch ($day)

          $day -in (1,21,31) "st"
          $day -in (2,22) "nd"
          $day -in (3,23) "rd"
          default "th"



          # Change to some other means of getting date - e.g. Read-Host
          $startDate = Get-Date "23/05/2007"

          # Get a collection of the month names (e.g. Jan, Feb, mar, etc)
          $months = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat.AbbreviatedMonthNames

          # Build the password from the date parts
          $password = "$($months[$startDate.Month-1])$($startDate.Day)$(Get-DaySuffix $startDate.Day)$($startDate.Year)!"


          In this case $password is set to May23rd2007!.






          share|improve this answer













          Repurposing the elegant C# solution here, you can do it like this in PowerShell:



           function Get-DaySuffix($day)

          switch ($day)

          $day -in (1,21,31) "st"
          $day -in (2,22) "nd"
          $day -in (3,23) "rd"
          default "th"



          # Change to some other means of getting date - e.g. Read-Host
          $startDate = Get-Date "23/05/2007"

          # Get a collection of the month names (e.g. Jan, Feb, mar, etc)
          $months = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat.AbbreviatedMonthNames

          # Build the password from the date parts
          $password = "$($months[$startDate.Month-1])$($startDate.Day)$(Get-DaySuffix $startDate.Day)$($startDate.Year)!"


          In this case $password is set to May23rd2007!.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 16:28









          boxdogboxdog

          3,4822515




          3,4822515





















              2














              Disclaimer: you probably already know, but I have to state that that's a very bad password, if you can even call it that




              Most of this can be offloaded to the DateTime type, all except for the ordinal suffixes for the day of the month.



              I would break it down into 3 steps:



              1. Parse input date

              2. Generate first half

              3. Calculate the suffix

              4. Append the year


              # Parse the input date
              $inputDate = Read-Host "Input date in the format MM/dd/yyyy"
              $date = [datetime]::ParseExact($inputDate,'MM/dd/yyyy',$null)

              # Generate first half
              $dateString = $date.ToString('MMMdd')

              # Calculate the ordinal suffix
              $day = $date.Day
              if($day -in 1,21,31)
              $dateString += 'st'

              else if($day -in 2,22)
              $dateString += 'nd'

              else if($day -in 3,23)
              $dateString += 'rd'

              else
              $dateString += 'th'


              # Append the year:
              $dateString += $date.ToString('yyyy!')





              share|improve this answer



























                2














                Disclaimer: you probably already know, but I have to state that that's a very bad password, if you can even call it that




                Most of this can be offloaded to the DateTime type, all except for the ordinal suffixes for the day of the month.



                I would break it down into 3 steps:



                1. Parse input date

                2. Generate first half

                3. Calculate the suffix

                4. Append the year


                # Parse the input date
                $inputDate = Read-Host "Input date in the format MM/dd/yyyy"
                $date = [datetime]::ParseExact($inputDate,'MM/dd/yyyy',$null)

                # Generate first half
                $dateString = $date.ToString('MMMdd')

                # Calculate the ordinal suffix
                $day = $date.Day
                if($day -in 1,21,31)
                $dateString += 'st'

                else if($day -in 2,22)
                $dateString += 'nd'

                else if($day -in 3,23)
                $dateString += 'rd'

                else
                $dateString += 'th'


                # Append the year:
                $dateString += $date.ToString('yyyy!')





                share|improve this answer

























                  2












                  2








                  2







                  Disclaimer: you probably already know, but I have to state that that's a very bad password, if you can even call it that




                  Most of this can be offloaded to the DateTime type, all except for the ordinal suffixes for the day of the month.



                  I would break it down into 3 steps:



                  1. Parse input date

                  2. Generate first half

                  3. Calculate the suffix

                  4. Append the year


                  # Parse the input date
                  $inputDate = Read-Host "Input date in the format MM/dd/yyyy"
                  $date = [datetime]::ParseExact($inputDate,'MM/dd/yyyy',$null)

                  # Generate first half
                  $dateString = $date.ToString('MMMdd')

                  # Calculate the ordinal suffix
                  $day = $date.Day
                  if($day -in 1,21,31)
                  $dateString += 'st'

                  else if($day -in 2,22)
                  $dateString += 'nd'

                  else if($day -in 3,23)
                  $dateString += 'rd'

                  else
                  $dateString += 'th'


                  # Append the year:
                  $dateString += $date.ToString('yyyy!')





                  share|improve this answer













                  Disclaimer: you probably already know, but I have to state that that's a very bad password, if you can even call it that




                  Most of this can be offloaded to the DateTime type, all except for the ordinal suffixes for the day of the month.



                  I would break it down into 3 steps:



                  1. Parse input date

                  2. Generate first half

                  3. Calculate the suffix

                  4. Append the year


                  # Parse the input date
                  $inputDate = Read-Host "Input date in the format MM/dd/yyyy"
                  $date = [datetime]::ParseExact($inputDate,'MM/dd/yyyy',$null)

                  # Generate first half
                  $dateString = $date.ToString('MMMdd')

                  # Calculate the ordinal suffix
                  $day = $date.Day
                  if($day -in 1,21,31)
                  $dateString += 'st'

                  else if($day -in 2,22)
                  $dateString += 'nd'

                  else if($day -in 3,23)
                  $dateString += 'rd'

                  else
                  $dateString += 'th'


                  # Append the year:
                  $dateString += $date.ToString('yyyy!')






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 16:34









                  Mathias R. JessenMathias R. Jessen

                  59.8k565110




                  59.8k565110



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323403%2fstring-manipulation-for-a-password%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Use pre created SQLite database for Android project in kotlin

                      Darth Vader #20

                      Ondo