malu.psm1
#---------------------------------------------------- #------------------ define classes ------------------ #---------------------------------------------------- #---------------------------------------------------- #------------- define private functions ------------- #---------------------------------------------------- Function Import-maluModule { [CmdletBinding()] param ( [Parameter( Mandatory = $true )] [System.String[]]$Name ) Begin { } Process { $Name | ForEach-Object { If(Get-module -ListAvailable -Name $_){ Import-Module -Name $_ -ErrorAction Stop } Else{ try { Install-Module -Name $_ -Force -AllowClobber -Scope CurrentUser -ErrorAction Stop Import-Module -Name $_ -ErrorAction Stop } catch { Throw ("Can't import the Module: " + $_) } } } } End { } } Function Get-RandomCharacter { param ( [string]$characters ) # Get one random character $randomIndex = Get-Random -Minimum 0 -Maximum ($characters.Length - 1) return $characters[$randomIndex] } #---------------------------------------------------- #-------------- define public functions ------------- #---------------------------------------------------- Function Get-RandomPasswordUser { [CmdletBinding()] param ( ) Begin { # Define lower- uppercase, special characters, numbers $lowercase = "abcdefghijklmnopqrstuvwxyz" $uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" $specialChars = "!@#$%^&*()_+=<>?" $numbers = "0123456789" $separators = "-_" # Define Password $password = "" } Process { # Add 4 uppercase Letters $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase # Add separator $password += Get-RandomCharacter -characters $separators # Add 4 lowercase Letters $password += Get-RandomCharacter -characters $lowercase $password += Get-RandomCharacter -characters $lowercase $password += Get-RandomCharacter -characters $lowercase $password += Get-RandomCharacter -characters $lowercase # Add separator $password += Get-RandomCharacter -characters $separators # Add 2 numbers $password += Get-RandomCharacter -characters $numbers $password += Get-RandomCharacter -characters $numbers # Add 2 special characters $password += Get-RandomCharacter -characters $specialChars $password += Get-RandomCharacter -characters $specialChars } End { Return $password } } Function Get-RandomPasswordAdmin { [CmdletBinding()] param ( ) Begin { # Define lower- uppercase, special characters, numbers $lowercase = "abcdefghijklmnopqrstuvwxyz" $uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" $specialChars = "!@#$%^&*()-+=<>?" $numbers = "0123456789" $separators = "_-" # Define Password $password = "" } Process { # Add 3 numbers $password += Get-RandomCharacter -characters $numbers $password += Get-RandomCharacter -characters $numbers $password += Get-RandomCharacter -characters $numbers # Add separator $password += Get-RandomCharacter -characters $separators # Add 3 lowercase letters $password += Get-RandomCharacter -characters $lowercase $password += Get-RandomCharacter -characters $lowercase $password += Get-RandomCharacter -characters $lowercase # Add separator $password += Get-RandomCharacter -characters $separators # Add 3 uppercase letters $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase # Add separator $password += Get-RandomCharacter -characters $separators # Add 3 special characters $password += Get-RandomCharacter -characters $specialChars $password += Get-RandomCharacter -characters $specialChars $password += Get-RandomCharacter -characters $specialChars # Add separator $password += Get-RandomCharacter -characters $separators # Add 3 numbers $password += Get-RandomCharacter -characters $numbers $password += Get-RandomCharacter -characters $numbers $password += Get-RandomCharacter -characters $numbers # Add separator $password += Get-RandomCharacter -characters $separators # Add 3 uppercase letters $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase $password += Get-RandomCharacter -characters $uppercase } End { Return $password } } |