J4T-PS-Generic.psm1
function Write-PipeLineInfoValue { [cmdletbinding()] param( [parameter( Mandatory = $true, ValueFromPipeline = $true)] $pipelineInput ) Process { ForEach ($input in $pipelineInput) { $input # if ($input.Name) { # Write-Host "Name: $($input.Name)" # } # elseif ($input.Path) { # Write-Host "Path: $($input.Path)"`n # } # else { # Write-Host $input # } } } } Export-ModuleMember -Function 'Write-PipeLineInfoValue' Function Get-Neat { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$Text ) process { $Text | ForEach-Object { $_.Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Trim() } } } Export-ModuleMember -Function 'Get-Neat' Function Get-TitleCase { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$Text ) process { $Text | ForEach-Object { (Get-Culture).TextInfo.ToTitleCase($_.ToLower()) } } } Export-ModuleMember -Function 'Get-TitleCase' Function Get-SpacedText { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$Text, [string] $Space = " " ) process { $ret += $Text | ForEach-Object { $_ | Split-Text -Delimit "." | Get-TitleCase } $ret } } Export-ModuleMember -Function 'Get-SpacedText' Function Split-Text { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string] $Text, [string] $Delimit = "," ) process { $Text.Split($Delimit) } } Export-ModuleMember -Function 'Split-Text' Function Get-Name { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$Name, [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$EmailAddress, [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$DistinguishedName ) process { $Name | ForEach-Object { Write-Host "Name: $_ " } $EmailAddress | ForEach-Object { Write-Host "EmailAddress: $_ " } $DistinguishedName | ForEach-Object { Write-Host "DistinguishedName: $_ " } } } Export-ModuleMember -Function 'Get-Name' function Get-Count { begin { $x = 0 } process { $x++ } end { $x } } Export-ModuleMember -Function 'Get-Count' Function Get-StrongPassword { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [int]$PasswordLenght = 15 ) process { Add-Type -AssemblyName System.Web $PassComplexCheck = $false do { [string]$NewPassword = [System.Web.Security.Membership]::GeneratePassword($PasswordLenght, 1) If ( ($NewPassword -cmatch "[A-Z\p{Lu}\s]") ` -and ($NewPassword -cmatch "[a-z\p{Ll}\s]") ` -and ($NewPassword -match "[\d]") ` -and ($NewPassword -match "[^\w]") ) { $PassComplexCheck = $True } } While ($PassComplexCheck -eq $false) $NewPassword.ToString() } } Export-ModuleMember -Function 'Get-StrongPassword' function Get-ScriptPath { $invocation = (Get-Variable MyInvocation).Value return Split-Path $invocation.PSCommandPath } Export-ModuleMember -Function 'Get-ScriptPath' function Get-ScriptName { $invocation = (Get-Variable MyInvocation).Value return (Split-Path $invocation.PSCommandPath -Leaf).Split(".")[0] } Export-ModuleMember -Function 'Get-ScriptName' function Get-LogPrint { [CmdletBinding()] Param( [Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [string[]]$Text ) process { # $Text | ForEach-Object { "$(Get-Date -Format "[yyyy-MM-dd HH:mm:ss.fff") $(Get-CallerScript)] $_" } $Text | ForEach-Object { "$(Get-Date -Format "[yyyy-MM-dd HH:mm:ss.fff")] $_" } } } Export-ModuleMember -Function 'Get-LogPrint' function Get-CallerScript { $i = (Get-PSCallStack).command.Length return (Get-PSCallStack).command[$i - 2] } Export-ModuleMember -Function 'Get-CallerScript' |