PSGISP.Tools.psm1

#---------------------------------------------
#------------------ Classes ------------------
#---------------------------------------------

#---------------------------------------------
#------------- Private Functions -------------
#---------------------------------------------

#---------------------------------------------
#-------------- Public Functions -------------
#---------------------------------------------
Function Get-Path {
    <#
        .SYNOPSIS
        GUI to choose path
 
        .DESCRIPTION
        This function opens a window to choose a specific path
 
        .PARAMETER RootFolder
        Folder in which the window will open
 
        .PARAMETER Description
        Window title
 
        .INPUTS
        You can pipe the value of the parameter (path) to this function / None
 
        .OUTPUTS
        System.Object[] / None
 
        .EXAMPLE
        Get-Path
 
        .LINK
        https://github.com/gisp497/psgisp
    #>

    [CmdletBinding()]
    param (
        [Parameter(
            Mandatory = $false,
            HelpMessage = "help message"
        )]
        [string]$RootFolder = [Environment]::GetFolderPath('Desktop'),
        [Parameter(
            Mandatory = $false,
            HelpMessage = "help message"
        )]
        [string]$Description = 'Select Folder or File'
    )
    Begin {
        #load assembly
        [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
    }
    Process {
        #create object
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        
        #set root folder
        $OpenFileDialog.initialDirectory = $RootFolder
        
        #remove filter
        $OpenFileDialog.filter = "All files (*.*)| *.*"
        
        #set windows title
        $OpenFileDialog.Title = $Description
        
        #show window
        $OpenFileDialog.ShowDialog() | Out-Null
    }
    End {
        #output value
        return $OpenFileDialog.filename
    }
}
Function Get-RandomString {
    <#
        .SYNOPSIS
        Creates random strings
 
        .DESCRIPTION
        This functions creates random strings. It is possible to generate Secure Strings.
 
        .PARAMETER Length
        Determined the length of the string.
 
         
        .PARAMETER Securestring
        Can be used, to generate securestrings.
 
        .INPUTS
        System.Int[]
        System.Switch[]
 
        .OUTPUTS
        System.String[]
        System.Securestring[]
 
        .EXAMPLE
        Get-RandomString -Length 23 -SecureString
 
        .LINK
        https://github.com/gisp497/psgisp
    #>

    [CmdletBinding()]
    param (
        [Parameter(
            Mandatory = $false,
            HelpMessage = "length of the password")]
        [int]$Length = 24,
        [Parameter(
            Mandatory = $false,
            HelpMessage = "number of special characters in password")]
        [int]$SpecialCharacter = 8,
        [Parameter(
            Mandatory = $false,
            HelpMessage = "Creates Output as secure string")]
        [switch]$SecureString = $false
    )
    Begin {
        #check if password lenght is bigger than special character number
        if ($SpecialCharacter -ge $Length){
            Throw "Can't use more special characters than password length."
        }

        #calculate password length
        $NormalCharacter = $Length - $SpecialCharacter

        #set of possible characters
        $Normal = Get-Random -Count $NormalCharacter -InputObject ([Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
        $Special = Get-Random -Count $SpecialCharacter -InputObject ([Char[]]'!#$%&*+-/=?@_')
        $StringSet = $Normal + $Special

    }
    Process {
        #Check if Securestring is wanted
        if ($SecureString) {
            $outputobject = (Get-Random -Count $Length -InputObject $StringSet) -join '' | ConvertTo-SecureString -AsPlainText -Force
        }else{
            [string]$outputobject = (Get-Random -Count $Length -InputObject $StringSet) -join ''
        }
        
    }
    End {
        #return value
        return $outputobject
    }
}

#---------------------------------------------
#--------- Export Public Functions -----------
#---------------------------------------------
$PublicFunctions = @(
    'Get-Path',
    'Get-RandomString'
)
Export-ModuleMember -Function $PublicFunctions