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;
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
add a comment |
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
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
add a comment |
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
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
powershell
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
1
shouldn't'1(1|2|3)$' 'th'
have a break to avoid an array?
– LotPings
Nov 15 '18 at 19:23
add a comment |
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!
.
add a comment |
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:
- Parse input date
- Generate first half
- Calculate the suffix
- 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!')
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
1
shouldn't'1(1|2|3)$' 'th'
have a break to avoid an array?
– LotPings
Nov 15 '18 at 19:23
add a comment |
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
1
shouldn't'1(1|2|3)$' 'th'
have a break to avoid an array?
– LotPings
Nov 15 '18 at 19:23
add a comment |
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
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
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
add a comment |
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
add a comment |
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!
.
add a comment |
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!
.
add a comment |
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!
.
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!
.
answered Nov 15 '18 at 16:28
boxdogboxdog
3,4822515
3,4822515
add a comment |
add a comment |
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:
- Parse input date
- Generate first half
- Calculate the suffix
- 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!')
add a comment |
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:
- Parse input date
- Generate first half
- Calculate the suffix
- 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!')
add a comment |
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:
- Parse input date
- Generate first half
- Calculate the suffix
- 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!')
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:
- Parse input date
- Generate first half
- Calculate the suffix
- 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!')
answered Nov 15 '18 at 16:34
Mathias R. JessenMathias R. Jessen
59.8k565110
59.8k565110
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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