Created
September 20, 2017 17:00
-
-
Save janegilring/23037acd52c94fe217df8dda091bff5a to your computer and use it in GitHub Desktop.
Quickly written PowerShell function for finding Norwegian baby names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Guttenavn | |
| $maledata = Invoke-WebRequest -Uri 'https://www.ssb.no/statistikkbanken/selectvarval/define.asp?SubjectCode=01&ProductId=01&MainTable=FornavnPersoner&contents=Personer&PLanguage=0&Qid=0&nvl=True&mt=1&pm=&SessID=3980226&FokusertBoks=1&gruppe1=Hele&gruppe2=Hele&VS1=NavnMenn01&VS2=&CMSSubjectArea=befolkning&KortNavnWeb=navn&StatVariant=&Tabstrip=SELECT&aggresetnr=1&checked=true' | |
| # Jentenavn | |
| $femaledata = Invoke-WebRequest -Uri 'https://www.ssb.no/statistikkbanken/selectvarval/define.asp?SubjectCode=01&ProductId=01&MainTable=FornavnPersoner&contents=Personer&PLanguage=0&Qid=0&nvl=True&mt=1&pm=&SessID=3980226&FokusertBoks=1&gruppe1=Hele&gruppe2=Hele&VS1=NavnKvinner01&VS2=&CMSSubjectArea=befolkning&KortNavnWeb=navn&StatVariant=&Tabstrip=SELECT&aggresetnr=1&checked=true' | |
| $malenames = @() | |
| $maledata.ParsedHtml.getElementsByTagName("OPTION") | foreach {$malenames += $_.text} | |
| $femalenames = @() | |
| $femaledata.ParsedHtml.getElementsByTagName("OPTION") | foreach {$femalenames += $_.text} | |
| function Find-BabyName { | |
| param ( | |
| [switch]$Boy, | |
| [switch]$Girl, | |
| [switch]$ShowAll | |
| ) | |
| if ($Boy) { | |
| if ($ShowAll) { | |
| $malenames | |
| } else { | |
| $malenames | Get-Random | |
| } | |
| } | |
| if ($Girl) { | |
| if ($ShowAll) { | |
| $femalenames | |
| } else { | |
| $femalenames | Get-Random | |
| } | |
| } | |
| } | |
| Find-BabyName -Girl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment