jhoek / UncommonSense.PowerShell.Utils

PowerShell utility cmdlets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UncommonSense.PowerShell.Utils

PowerShell utility cmdlets

Index

Command Synopsis
Find-Application Shows in which folder the given (native) command resides
Find-InFiles Performs an (optionally recursive) file search based on a regular expression
Find-UniqueFileName Find-UniqueFileName [-Path] [[-MaxAttempts] ] [-CreateFile] []
Format-HashTable Pretty-prints a (nested) hash table
Format-Object Pretty-prints a (nested) object
Get-CommandInSameModule Gets a list of commands that live in the same module as the given command.
Get-ContiguousRange Returns the first item or all items of the first contiguous range of items of the specified length
Get-DropboxPath Get-DropboxPath
Get-FormattedText Get-FormattedText [[-Text] <string[]>] [-BackgroundColor ] [-ForegroundColor ] [-BackgroundBright] [-ForegroundBright] [-Negative] [-Underline] []
Get-FriendlyTypeName Get-FriendlyTypeName [-Type] <type[]> [-NullableFormat ] [-GenericFormat ] [-ArrayFormat ] []
Get-PropertyValueOrDefault Get-PropertyValueOrDefault [-PropertyName] [[-DefaultValue] ] -Object <Object[]> []
Get-ValueOrDefault Returns the value that was passed in, or, if that value was null, blank, zero or empty, returns the specified default value. If value may refer to an undefined element in an array or hashtable, wrap $Value in a scriptblock to prevent premature evaluation.
Set-BreakOnError Sets a breakpoint that causes the debugger to break on the first run-time error
Split-Collection Splits a collection into chuncks of a given size
Test-NullableType Test-NullableType [-Type] []

Find-Application

Synopsis

Shows in which folder the given (native) command resides

Syntax

Find-Application [-Command] <string> [<CommonParameters>]

Parameters

Command <String>

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Find-InFiles

Synopsis

Performs an (optionally recursive) file search based on a regular expression

Syntax

Find-InFiles [-Pattern] <string> [-Path <Object>] [-Filter <string>] [-Recurse] [-Context <int[]>] [<CommonParameters>]

Parameters

Pattern <String>

Required?                    true
Position?                    2
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Path <Object>

Required?                    false
Position?                    named
Default value                $Pwd
Accept pipeline input?       false
Accept wildcard characters?  false

Filter <String>

Required?                    false
Position?                    named
Default value                *.*
Accept pipeline input?       false
Accept wildcard characters?  false

Recurse [<SwitchParameter>]

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Accept wildcard characters?  false

Context <Int32[]>

Required?                    false
Position?                    named
Default value                0
Accept pipeline input?       false
Accept wildcard characters?  false

Find-UniqueFileName

Synopsis

Find-UniqueFileName [-Path] [[-MaxAttempts] ] [-CreateFile] []

Syntax

Find-UniqueFileName [-Path] <string> [[-MaxAttempts] <int>] [-CreateFile] [<CommonParameters>]

Parameters

CreateFile

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

MaxAttempts <int>

Required?                    false
Position?                    1
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Path <string>

Required?                    true
Position?                    0
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Format-HashTable

Synopsis

Pretty-prints a (nested) hash table

Syntax

Format-HashTable [-HashTable] <IDictionary[]> [[-Indentation] <int>] [<CommonParameters>]

Parameters

HashTable <IDictionary[]>

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       true (ByValue)
Accept wildcard characters?  false

Indentation <Int32>

Required?                    false
Position?                    2
Default value                0
Accept pipeline input?       false
Accept wildcard characters?  false

Format-Object

Synopsis

Pretty-prints a (nested) object

Syntax

Format-Object [-Caption] <string> [-Value] <Object> [[-Indentation] <int>] [<CommonParameters>]

Parameters

Caption <String>

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Value <Object>

Required?                    true
Position?                    2
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Indentation <Int32>

Required?                    false
Position?                    3
Default value                0
Accept pipeline input?       false
Accept wildcard characters?  false

Get-CommandInSameModule

Synopsis

Gets a list of commands that live in the same module as the given command.

Syntax

Get-CommandInSameModule [-Name] <string> [<CommonParameters>]

Parameters

Name <String>

The name of the command whose sibling commands should be displayed

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Get-ContiguousRange

Synopsis

Returns the first item or all items of the first contiguous range of items of the specified length

Syntax

Get-ContiguousRange [-Items] <int[]> [[-RequiredLength] <int>] [-ReturnAll] [<CommonParameters>]

Parameters

Items <Int32[]>

The items in which the contiguous range is to be found

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       true (ByValue)
Accept wildcard characters?  false

RequiredLength <Int32>

The required number of contiguous items

Required?                    false
Position?                    2
Default value                1
Accept pipeline input?       false
Accept wildcard characters?  false

ReturnAll [<SwitchParameter>]

If true, all contiguous items are returned; if false, only the first item in the range is returned

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Accept wildcard characters?  false

Examples

Example 1

1..20 | ForEach-Object { Get-ContiguousRange -Items (1..9 + 25..35 + 50..90) -RequiredLength $_ }

Get-DropboxPath

Synopsis

Get-DropboxPath

Syntax

Get-DropboxPath

Parameters

Get-FormattedText

Synopsis

Get-FormattedText [[-Text] <string[]>] [-BackgroundColor ] [-ForegroundColor ] [-BackgroundBright] [-ForegroundBright] [-Negative] [-Underline] []

Syntax

Get-FormattedText [[-Text] <string[]>] [-BackgroundColor <string>] [-ForegroundColor <string>] [-BackgroundBright] [-ForegroundBright] [-Negative] [-Underline] [<CommonParameters>]

Parameters

BackgroundBright

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

BackgroundColor <string>

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

ForegroundBright

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

ForegroundColor <string>

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Negative

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Text <string[]>

Required?                    false
Position?                    1
Accept pipeline input?       true (ByValue)
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Underline

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Get-FriendlyTypeName

Synopsis

Get-FriendlyTypeName [-Type] <type[]> [-NullableFormat ] [-GenericFormat ] [-ArrayFormat ] []

Syntax

Get-FriendlyTypeName [-Type] <type[]> [-NullableFormat <string>] [-GenericFormat <string>] [-ArrayFormat <string>] [<CommonParameters>]

Output Type(s)

  • System.String

Parameters

ArrayFormat <string>

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

GenericFormat <string>

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

NullableFormat <string>

Required?                    false
Position?                    Named
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Type <type[]>

Required?                    true
Position?                    0
Accept pipeline input?       true (ByValue)
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Get-PropertyValueOrDefault

Synopsis

Get-PropertyValueOrDefault [-PropertyName] [[-DefaultValue] ] -Object <Object[]> []

Syntax

Get-PropertyValueOrDefault [-PropertyName] <string> [[-DefaultValue] <Object>] -Object <Object[]> [<CommonParameters>]

Parameters

DefaultValue <Object>

Required?                    false
Position?                    1
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Object <Object[]>

Required?                    true
Position?                    Named
Accept pipeline input?       true (ByValue)
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

PropertyName <string>

Required?                    true
Position?                    0
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false

Get-ValueOrDefault

Synopsis

Returns the value that was passed in, or, if that value was null, blank, zero or empty, returns the specified default value.

If value may refer to an undefined element in an array or hashtable, wrap $Value in a scriptblock to prevent premature evaluation.

Syntax

Get-ValueOrDefault [[-DefaultValue] <Object>] [-Value <Object>] [<CommonParameters>]

Parameters

Value <Object>

Required?                    false
Position?                    named
Default value                
Accept pipeline input?       true (ByValue)
Accept wildcard characters?  false

DefaultValue <Object>

Required?                    false
Position?                    2
Default value                
Accept pipeline input?       false
Accept wildcard characters?  false

Examples

Example 1

('A' | ?? B) -eq "A" # returns True

Example 2

('' | ?? C) -eq 'C' # returns True

Example 3

($null | ?? D) -eq 'D' # returns True

Example 4

(1 | ?? 2) -eq 1 # returns True

Example 5

(0 | ?? 3) -eq 3 # returns True

Example 6

('A' -as [int] | ?? E) -eq 'E' # returns True

Example 7

($false | ?? F) -eq 'F' # returns True

Example 8

($true | ?? G) -eq $true # returns True

Example 9

({ @()[3] } | ?? H) -eq 'H' # returns True

Example 10

({ @{}.Foo.Baz} | ?? I) -eq 'I' #returns True

Set-BreakOnError

Synopsis

Sets a breakpoint that causes the debugger to break on the first run-time error

Syntax

Set-BreakOnError

Split-Collection

Synopsis

Splits a collection into chuncks of a given size

Syntax

Split-Collection [-Collection] <psobject[]> [-ChunkSize] <int> [<CommonParameters>]

Parameters

Collection <PSObject[]>

Required?                    true
Position?                    1
Default value                
Accept pipeline input?       true (ByValue)
Accept wildcard characters?  false

ChunkSize <Int32>

Required?                    true
Position?                    2
Default value                0
Accept pipeline input?       false
Accept wildcard characters?  false

Examples

Example 1

$Collection = (65..90) | ForEach-Object { [char]$_ }

$Collection | Split-Collection -ChunkSize 3 | Select-Object -Skip 3 -First 1

Example 2

$Collection = (65..90) | ForEach-Object { [char]$_ }

Split-Collection -Collection $Collection -ChunkSize 5 | Select-Object -Skip 3 -First 1

Example 3

$EmptyCollection = @()

$EmptyCollection | Split-Collection -ChunkSize 2 | Measure-Object

Test-NullableType

Synopsis

Test-NullableType [-Type] []

Syntax

Test-NullableType [-Type] <type> [<CommonParameters>]

Output Type(s)

  • System.Boolean

Parameters

Type <type>

Required?                    true
Position?                    0
Accept pipeline input?       false
Parameter set name           (All)
Aliases                      None
Dynamic?                     false
Generated 07-03-2019 22:19

About

PowerShell utility cmdlets

License:GNU General Public License v3.0


Languages

Language:PowerShell 100.0%