29 | $H = $H -replace '<[^>]+>', ''
30 | }
31 | # This replaces chars to their clean equivalent
32 | $H -replace '“', '"' -replace '’', "'" -replace '”', '"' -replace '…', '...' -replace '—', '-' -replace '–', '-'
33 | }
34 | }
--------------------------------------------------------------------------------
/Private/Deprecated/ActiveDirectory/Find-ExchangeServer.ps1:
--------------------------------------------------------------------------------
1 | function Find-ExchangeServer {
2 | <#
3 | .SYNOPSIS
4 | Find Exchange Servers in Active Directory
5 |
6 | .DESCRIPTION
7 | Find Exchange Servers in Active Directory
8 |
9 | .EXAMPLE
10 | Find-ExchangeServer
11 |
12 | .NOTES
13 | General notes
14 | #>
15 | [CmdletBinding()]
16 | param(
17 |
18 | )
19 | $ExchangeServers = Get-ADGroup -Identity "Exchange Servers"
20 | foreach ($Server in $ExchangeServers) {
21 | $Data = Get-ADComputer -Identity $Server.SamAccountName -Properties Name, DNSHostName, OperatingSystem, DistinguishedName, ServicePrincipalName
22 | [PSCustomObject] @{
23 | Name = $Data.Name
24 | FQDN = $Data.DNSHostName
25 | OperatingSystem = $Data.OperatingSystem
26 | DistinguishedName = $Data.DistinguishedName
27 | Enabled = $Data.Enabled
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Private/Deprecated/ActiveDirectory/Get-WinADOrganizationalUnitFromDN.ps1:
--------------------------------------------------------------------------------
1 | function Get-WinADOrganizationalUnitFromDN {
2 | <#
3 | .SYNOPSIS
4 | This function extracts the Organizational Unit (OU) from a given Distinguished Name (DN).
5 |
6 | .DESCRIPTION
7 | This function takes a Distinguished Name (DN) as input and returns the Organizational Unit (OU) part of it.
8 |
9 | .PARAMETER DistinguishedName
10 | Specifies the Distinguished Name (DN) from which to extract the Organizational Unit (OU).
11 |
12 | .EXAMPLE
13 | Extract the Organizational Unit (OU) from a Distinguished Name.
14 |
15 | $DistinguishedName = 'CN=Przemyslaw Klys,OU=Users,OU=Production,DC=ad,DC=evotec,DC=xyz'
16 | Get-WinADOrganizationalUnitFromDN -DistinguishedName $DistinguishedName
17 |
18 | .NOTES
19 | This function uses regular expressions to extract the Organizational Unit (OU) from the given Distinguished Name (DN).
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | $DistinguishedName
24 | )
25 | return [Regex]::Match($DistinguishedName,'(?=OU)(.*\n?)(?<=.)').Value
26 | }
--------------------------------------------------------------------------------
/Private/Deprecated/ActiveDirectory/Get-WinADUsersByOU.ps1:
--------------------------------------------------------------------------------
1 | function Get-WinADUsersByOU {
2 | <#
3 | .SYNOPSIS
4 | Retrieves Active Directory users within a specified Organizational Unit.
5 |
6 | .DESCRIPTION
7 | This function retrieves Active Directory users within the specified Organizational Unit.
8 |
9 | .PARAMETER OrganizationalUnit
10 | Specifies the Organizational Unit from which to retrieve users.
11 |
12 | .EXAMPLE
13 | Get-WinADUsersByOU -OrganizationalUnit "OU=Sales,DC=Contoso,DC=com"
14 | Retrieves all users within the Sales Organizational Unit in the Contoso domain.
15 |
16 | #>
17 | [CmdletBinding()]
18 | param (
19 | $OrganizationalUnit
20 | )
21 | $OU = Get-ADOrganizationalUnit $OrganizationalUnit
22 | if ($OU.ObjectClass -eq 'OrganizationalUnit') {
23 | try {
24 | $Users = Get-ADUser -SearchBase $OU -Filter * -Properties $Script:UserProperties
25 | } catch {
26 | Write-Color @Script:WriteParameters -Text '[i]', ' One or more properties are invalid - Terminating', ' Terminating' -Color Yellow, White, Red
27 | return
28 | }
29 | }
30 | return $Users
31 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesCurrentDayMinusDayX.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesCurrentDayMinusDayX ($days) {
2 | <#
3 | .SYNOPSIS
4 | Finds the date range for the current day minus a specified number of days.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates for the current day minus a specified number of days.
8 |
9 | .PARAMETER days
10 | Specifies the number of days to subtract from the current day.
11 |
12 | .EXAMPLE
13 | Find-DatesCurrentDayMinusDayX -days 1
14 | Returns the date range for yesterday.
15 |
16 | .EXAMPLE
17 | Find-DatesCurrentDayMinusDayX -days 7
18 | Returns the date range for a week ago.
19 |
20 | #>
21 | $DateTodayStart = (Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).AddDays( - $Days)
22 | $DateTodayEnd = (Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).AddDays(1).AddDays( - $Days).AddMilliseconds(-1)
23 |
24 | $DateParameters = @{
25 | DateFrom = $DateTodayStart
26 | DateTo = $DateTodayEnd
27 | }
28 | return $DateParameters
29 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesCurrentDayMinuxDaysX.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesCurrentDayMinuxDaysX ($days) {
2 | <#
3 | .SYNOPSIS
4 | Finds the date range for the current day minus a specified number of days.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates for the current day minus a specified number of days.
8 |
9 | .PARAMETER days
10 | Specifies the number of days to subtract from the current day.
11 |
12 | .EXAMPLE
13 | Find-DatesCurrentDayMinuxDaysX -days 1
14 | Returns the date range for yesterday.
15 |
16 | .EXAMPLE
17 | Find-DatesCurrentDayMinuxDaysX -days 7
18 | Returns the date range for a week ago.
19 | #>
20 | $DateTodayStart = (Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).AddDays( - $Days)
21 | $DateTodayEnd = (Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).AddDays(1).AddMilliseconds(-1)
22 |
23 | $DateParameters = @{
24 | DateFrom = $DateTodayStart
25 | DateTo = $DateTodayEnd
26 | }
27 | return $DateParameters
28 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesCurrentHour.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesCurrentHour () {
2 | <#
3 | .SYNOPSIS
4 | Finds the start and end dates for the current hour.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates for the current hour.
8 |
9 | .EXAMPLE
10 | PS C:\> Find-DatesCurrentHour
11 | DateFrom DateTo
12 | -------- ------
13 | 10/20/2021 12:00:00 AM 10/20/2021 1:00:00 AM
14 | #>
15 | $DateTodayStart = (Get-Date -Minute 0 -Second 0 -Millisecond 0)
16 | $DateTodayEnd = $DateTodayStart.AddHours(1)
17 |
18 | $DateParameters = @{
19 | DateFrom = $DateTodayStart
20 | DateTo = $DateTodayEnd
21 | }
22 | return $DateParameters
23 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesDayPrevious.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesDayPrevious () {
2 | <#
3 | .SYNOPSIS
4 | Finds the date parameters for the previous day.
5 |
6 | .DESCRIPTION
7 | This function calculates the date parameters for the previous day based on the current date.
8 |
9 | .EXAMPLE
10 | Find-DatesDayPrevious
11 | Returns the date parameters for the previous day.
12 |
13 | #>
14 | $DateToday = (GET-DATE).Date
15 | $DateYesterday = $DateToday.AddDays(-1)
16 |
17 | $DateParameters = @{
18 | DateFrom = $DateYesterday
19 | DateTo = $dateToday
20 | }
21 | return $DateParameters
22 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesDayToday.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesDayToday () {
2 | <#
3 | .SYNOPSIS
4 | Finds the start and end dates of the current day.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates of the current day based on the current date.
8 | #>
9 | $DateToday = (GET-DATE).Date
10 | $DateTodayEnd = $DateToday.AddDays(1).AddSeconds(-1)
11 |
12 | $DateParameters = @{
13 | DateFrom = $DateToday
14 | DateTo = $DateTodayEnd
15 | }
16 | return $DateParameters
17 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesMonthCurrent.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesMonthCurrent () {
2 | <#
3 | .SYNOPSIS
4 | Finds the start and end dates of the current month.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates of the current month based on the current date.
8 |
9 | .EXAMPLE
10 | Find-DatesMonthCurrent
11 | Returns the start and end dates of the current month.
12 |
13 | #>
14 | $DateMonthFirstDay = (GET-DATE -Day 1).Date
15 | $DateMonthLastDay = GET-DATE $DateMonthFirstDay.AddMonths(1).AddSeconds(-1)
16 |
17 | $DateParameters = @{
18 | DateFrom = $DateMonthFirstDay
19 | DateTo = $DateMonthLastDay
20 | }
21 | return $DateParameters
22 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesMonthPast.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesMonthPast ([bool] $Force) {
2 | <#
3 | .SYNOPSIS
4 | Finds the dates for the previous month based on the current date.
5 |
6 | .DESCRIPTION
7 | This function calculates the date range for the previous month based on the current date. It returns the start and end dates of the previous month.
8 |
9 | .PARAMETER Force
10 | If set to $true, the function will always return the date range for the previous month, regardless of the current date.
11 |
12 | .EXAMPLE
13 | Find-DatesMonthPast -Force $false
14 | Returns $null if the current date is not the first day of the month.
15 |
16 | .EXAMPLE
17 | Find-DatesMonthPast -Force $true
18 | Returns the date range for the previous month even if the current date is not the first day of the month.
19 | #>
20 | $DateToday = (Get-Date).Date
21 | $DateMonthFirstDay = (GET-DATE -Day 1).Date
22 | $DateMonthPreviousFirstDay = $DateMonthFirstDay.AddMonths(-1)
23 |
24 | if ($Force -eq $true -or $DateToday -eq $DateMonthFirstDay) {
25 | $DateParameters = @{
26 | DateFrom = $DateMonthPreviousFirstDay
27 | DateTo = $DateMonthFirstDay
28 | }
29 | return $DateParameters
30 | } else {
31 | return $null
32 | }
33 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesPastHour.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesPastHour () {
2 | <#
3 | .SYNOPSIS
4 | Finds the date range for the past hour.
5 |
6 | .DESCRIPTION
7 | This function calculates the date range for the past hour, starting from the beginning of the previous hour up to the current hour.
8 |
9 | .EXAMPLE
10 | Find-DatesPastHour
11 | Returns a hashtable with DateFrom and DateTo keys representing the date range for the past hour.
12 |
13 | #>
14 | $DateTodayEnd = Get-Date -Minute 0 -Second 0 -Millisecond 0
15 | $DateTodayStart = $DateTodayEnd.AddHours(-1)
16 |
17 | $DateParameters = @{
18 | DateFrom = $DateTodayStart
19 | DateTo = $DateTodayEnd
20 | }
21 | return $DateParameters
22 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesPastWeek.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesPastWeek($DayName) {
2 | <#
3 | .SYNOPSIS
4 | Finds the date range for the past week based on the specified day.
5 |
6 | .DESCRIPTION
7 | This function calculates the date range for the past week based on the specified day of the week.
8 |
9 | .PARAMETER DayName
10 | The day of the week to use as a reference for finding the past week's date range.
11 |
12 | .EXAMPLE
13 | Find-DatesPastWeek -DayName "Monday"
14 | Returns the date range for the past week starting from the previous Monday.
15 |
16 | .EXAMPLE
17 | Find-DatesPastWeek -DayName "Friday"
18 | Returns the date range for the past week starting from the previous Friday.
19 |
20 | #>
21 | $DateTodayStart = Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0
22 | if ($DateTodayStart.DayOfWeek -ne $DayName) {
23 | return $null
24 | }
25 | $DateTodayEnd = (Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).AddDays(-7)
26 | $DateParameters = @{
27 | DateFrom = $DateTodayEnd
28 | DateTo = $DateTodayStart
29 | }
30 | return $DateParameters
31 |
32 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Dates/Find-DatesQuarterCurrent.ps1:
--------------------------------------------------------------------------------
1 | function Find-DatesQuarterCurrent ([bool] $Force) {
2 | <#
3 | .SYNOPSIS
4 | Finds the start and end dates of the current quarter.
5 |
6 | .DESCRIPTION
7 | This function calculates the start and end dates of the current quarter based on the current date.
8 |
9 | .PARAMETER Force
10 | If set to $true, forces the function to recalculate the dates even if they have been previously calculated.
11 |
12 | .EXAMPLE
13 | Find-DatesQuarterCurrent -Force $false
14 | Returns the start and end dates of the current quarter without recalculating if already calculated.
15 |
16 | .EXAMPLE
17 | Find-DatesQuarterCurrent -Force $true
18 | Forces the function to recalculate and returns the start and end dates of the current quarter.
19 |
20 | #>
21 | $Today = (Get-Date)
22 | $Quarter = [Math]::Ceiling($Today.Month / 3)
23 | $LastDay = [DateTime]::DaysInMonth([Int]$Today.Year.ToString(), [Int]($Quarter * 3))
24 | $StartDate = (get-date -Year $Today.Year -Month ($Quarter * 3 - 2) -Day 1).Date
25 | $EndDate = (get-date -Year $Today.Year -Month ($Quarter * 3) -Day $LastDay).Date.AddDays(1).AddTicks(-1)
26 | $DateParameters = @{
27 | DateFrom = $StartDate
28 | DateTo = $EndDate
29 | }
30 | return $DateParameters
31 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Email/Get-HTML.ps1:
--------------------------------------------------------------------------------
1 | function Get-HTML {
2 | <#
3 | .SYNOPSIS
4 | Splits the input text by carriage return and outputs each line.
5 |
6 | .DESCRIPTION
7 | This function takes a string input and splits it by carriage return (`r) to output each line separately.
8 |
9 | .PARAMETER text
10 | The input text to be split and displayed line by line.
11 |
12 | .EXAMPLE
13 | Get-HTML -text "Line 1`rLine 2`rLine 3"
14 | This example splits the input text by carriage return and outputs each line separately.
15 |
16 | #>
17 | [CmdletBinding()]
18 | param (
19 | [string] $text
20 | )
21 | $text = $text.Split("`r")
22 | foreach ($t in $text) {
23 | Write-Host $t
24 | }
25 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Email/Set-EmailBodyPreparedTable.ps1:
--------------------------------------------------------------------------------
1 | function Set-EmailBodyPreparedTable ($TableData, $TableWelcomeMessage) {
2 | <#
3 | .SYNOPSIS
4 | Prepares the email body with a welcome message and table data.
5 |
6 | .DESCRIPTION
7 | This function prepares the email body by combining a welcome message and table data into a single HTML string.
8 |
9 | .PARAMETER TableData
10 | The data to be included in the email body table.
11 |
12 | .PARAMETER TableWelcomeMessage
13 | The welcome message to be displayed at the beginning of the email body.
14 |
15 | .EXAMPLE
16 | $tableData = "
John
Doe
"
17 | $welcomeMessage = "Welcome to our platform!"
18 | Set-EmailBodyPreparedTable -TableData $tableData -TableWelcomeMessage $welcomeMessage
19 |
20 | This example prepares the email body with a welcome message "Welcome to our platform!" and table data "
John
Doe
".
21 |
22 | #>
23 | $body = "
$TableWelcomeMessage
"
24 | $body += $TableData
25 | return $body
26 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Email/Set-EmailWordReplacementsHash.ps1:
--------------------------------------------------------------------------------
1 | function Set-EmailWordReplacementsHash {
2 | <#
3 | .SYNOPSIS
4 | Replaces words in an email body based on a given hash table of substitutions.
5 |
6 | .DESCRIPTION
7 | This function replaces words in the email body with specified substitutions using a hash table.
8 |
9 | .PARAMETER Body
10 | The email body where the word replacements will be applied.
11 |
12 | .PARAMETER Substitute
13 | A hash table containing the words to be replaced as keys and their corresponding substitutions as values.
14 |
15 | .EXAMPLE
16 | $body = "Hello, my name is John."
17 | $substitutions = @{
18 | "John" = "Jane"
19 | }
20 | Set-EmailWordReplacementsHash -Body $body -Substitute $substitutions
21 | # This will replace "John" with "Jane" in the email body.
22 |
23 | #>
24 | [CmdletBinding()]
25 | param (
26 | $Body,
27 | $Substitute
28 | )
29 | foreach ($Key in $Substitute.Keys) {
30 | Write-Verbose "Set-EmailWordReplacementsHash - Key: $Key Value: $($Substitute.$Key)"
31 | $Body = Set-EmailWordReplacements -Body $Body -Replace $Key -ReplaceWith $Substitute.$Key
32 | }
33 | return $Body
34 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Add-ToArray.ps1:
--------------------------------------------------------------------------------
1 | function Add-ToArray {
2 | <#
3 | .SYNOPSIS
4 | Adds an element to an ArrayList.
5 |
6 | .DESCRIPTION
7 | This function adds an element to the specified ArrayList.
8 |
9 | .PARAMETER List
10 | The ArrayList to which the element will be added.
11 |
12 | .PARAMETER Element
13 | The element to be added to the ArrayList.
14 |
15 | .EXAMPLE
16 | $myList = New-Object System.Collections.ArrayList
17 | Add-ToArray -List $myList -Element "Apple"
18 | # Adds the string "Apple" to the ArrayList $myList.
19 |
20 | .EXAMPLE
21 | $myList = New-Object System.Collections.ArrayList
22 | Add-ToArray -List $myList -Element 42
23 | # Adds the integer 42 to the ArrayList $myList.
24 | #>
25 | [CmdletBinding()]
26 | param(
27 | [System.Collections.ArrayList] $List,
28 | [Object] $Element
29 | )
30 | #Write-Verbose "Add-ToArray - Element: $Element"
31 | [void] $List.Add($Element) #> $null
32 | }
33 |
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Add-ToHashTable.ps1:
--------------------------------------------------------------------------------
1 | function Add-ToHashTable($Hashtable, $Key, $Value) {
2 | <#
3 | .SYNOPSIS
4 | Adds a key-value pair to a hashtable.
5 |
6 | .DESCRIPTION
7 | This function adds a key-value pair to a given hashtable. If the value is not null or empty, it is added to the hashtable.
8 |
9 | .PARAMETER Hashtable
10 | The hashtable to which the key-value pair will be added.
11 |
12 | .PARAMETER Key
13 | The key of the key-value pair to be added.
14 |
15 | .PARAMETER Value
16 | The value of the key-value pair to be added.
17 |
18 | .EXAMPLE
19 | $myHashtable = @{}
20 | Add-ToHashTable -Hashtable $myHashtable -Key "Name" -Value "John"
21 | # Adds the key-value pair "Name"-"John" to $myHashtable.
22 |
23 | .EXAMPLE
24 | $myHashtable = @{}
25 | Add-ToHashTable -Hashtable $myHashtable -Key "Age" -Value 25
26 | # Adds the key-value pair "Age"-25 to $myHashtable.
27 | #>
28 | if ($null -ne $Value -and $Value -ne '') {
29 | $Hashtable.Add($Key, $Value)
30 | }
31 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Get-HashMaxValue.ps1:
--------------------------------------------------------------------------------
1 | function Get-HashMaxValue {
2 | <#
3 | .SYNOPSIS
4 | Gets the maximum value from a hashtable.
5 |
6 | .DESCRIPTION
7 | This function retrieves the maximum value from a given hashtable. It can also return the minimum value if the -Lowest switch is used.
8 |
9 | .PARAMETER hashTable
10 | The hashtable from which to find the maximum value.
11 |
12 | .PARAMETER Lowest
13 | If specified, the function will return the minimum value instead of the maximum.
14 |
15 | .EXAMPLE
16 | $myHashTable = @{ 'A' = 10; 'B' = 20; 'C' = 5 }
17 | Get-HashMaxValue -hashTable $myHashTable
18 | # Output: 20
19 |
20 | .EXAMPLE
21 | $myHashTable = @{ 'A' = 10; 'B' = 20; 'C' = 5 }
22 | Get-HashMaxValue -hashTable $myHashTable -Lowest
23 | # Output: 5
24 | #>
25 | [CmdletBinding()]
26 | param (
27 | [Object] $hashTable,
28 | [switch] $Lowest
29 | )
30 | if ($Lowest) {
31 | return ($hashTable.GetEnumerator() | Sort-Object value -Descending | Select-Object -Last 1).Value
32 | } else {
33 | return ($hashTable.GetEnumerator() | Sort-Object value -Descending | Select-Object -First 1).Value
34 | }
35 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Get-ObjectCount.ps1:
--------------------------------------------------------------------------------
1 | function Get-ObjectCount {
2 | <#
3 | .SYNOPSIS
4 | Counts the number of objects passed as input.
5 |
6 | .DESCRIPTION
7 | This function calculates and returns the total count of objects passed as input. It is designed to be used in scenarios where counting the number of objects is required.
8 |
9 | .PARAMETER Object
10 | Specifies the object or objects for which the count needs to be calculated.
11 |
12 | .EXAMPLE
13 | Get-Process | Get-ObjectCount
14 | Returns the total count of processes currently running.
15 |
16 | .EXAMPLE
17 | $Files = Get-ChildItem -Path "C:\Files"
18 | $FileCount = $Files | Get-ObjectCount
19 | Returns the total count of files in the specified directory.
20 |
21 | #>
22 | [CmdletBinding()]
23 | param(
24 | [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Object]$Object
25 | )
26 | return $($Object | Measure-Object).Count
27 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Get-ObjectEnumValues.ps1:
--------------------------------------------------------------------------------
1 | Function Get-ObjectEnumValues {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the values of an enumeration type and returns them as a hashtable.
5 |
6 | .DESCRIPTION
7 | This function takes an enumeration type as input and retrieves all its values, storing them in a hashtable where the key is the name of the enum value and the value is the corresponding numeric value.
8 |
9 | .PARAMETER enum
10 | Specifies the enumeration type for which values need to be retrieved.
11 |
12 | .EXAMPLE
13 | Get-ObjectEnumValues -enum [System.DayOfWeek]
14 | Retrieves all values of the System.DayOfWeek enumeration and returns them as a hashtable.
15 |
16 | .EXAMPLE
17 | Get-ObjectEnumValues -enum [System.ConsoleColor]
18 | Retrieves all values of the System.ConsoleColor enumeration and returns them as a hashtable.
19 |
20 | #>
21 | param(
22 | [string]$enum
23 | )
24 | $enumValues = @{}
25 | [enum]::getvalues([type]$enum) |
26 | ForEach-Object {
27 | $enumValues.add($_, $_.value__)
28 | }
29 | $enumValues
30 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Get-ObjectKeys.ps1:
--------------------------------------------------------------------------------
1 | function Get-ObjectKeys {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the keys of an object excluding a specified key.
5 |
6 | .DESCRIPTION
7 | This function retrieves the keys of an object while excluding a specified key. It returns an array of keys from the object.
8 |
9 | .PARAMETER Object
10 | The object from which keys need to be retrieved.
11 |
12 | .PARAMETER Ignore
13 | The key to be excluded from the result.
14 |
15 | .EXAMPLE
16 | $object = @{ 'key1' = 'value1'; 'key2' = 'value2'; 'key3' = 'value3' }
17 | Get-ObjectKeys -Object $object -Ignore 'key2'
18 | # Returns 'key1', 'key3'
19 |
20 | #>
21 | param(
22 | [object] $Object,
23 | [string] $Ignore
24 | )
25 | $Data = $Object.Keys | Where-Object { $_ -notcontains $Ignore }
26 | return $Data
27 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/Get-ObjectTitles.ps1:
--------------------------------------------------------------------------------
1 | function Get-ObjectTitles {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the titles of properties from an object.
5 |
6 | .DESCRIPTION
7 | This function retrieves the titles of properties from an object and returns them in an ArrayList.
8 |
9 | .PARAMETER Object
10 | Specifies the object from which to retrieve property titles.
11 |
12 | .EXAMPLE
13 | $object = [PSCustomObject]@{
14 | Name = "John Doe"
15 | Age = 30
16 | City = "New York"
17 | }
18 | Get-ObjectTitles -Object $object
19 |
20 | Description
21 | -----------
22 | Retrieves the property titles from the $object and returns them in an ArrayList.
23 |
24 | #>
25 | [CmdletBinding()]
26 | param(
27 | $Object
28 | )
29 | $ArrayList = New-Object System.Collections.ArrayList
30 | Write-Verbose "Get-ObjectTitles - ObjectType $($Object.GetType())"
31 | foreach ($Title in $Object.PSObject.Properties) {
32 | Write-Verbose "Get-ObjectTitles - Value added to array: $($Title.Name)"
33 | $ArrayList.Add($Title.Name) | Out-Null
34 | }
35 | Write-Verbose "Get-ObjectTitles - Array size: $($ArrayList.Count)"
36 | return $ArrayList
37 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/New-ArrayList.ps1:
--------------------------------------------------------------------------------
1 | function New-ArrayList {
2 | <#
3 | .SYNOPSIS
4 | Creates a new ArrayList object.
5 |
6 | .DESCRIPTION
7 | This function creates a new instance of the ArrayList class from the System.Collections namespace.
8 |
9 | .EXAMPLE
10 | $myList = New-ArrayList
11 | $myList.Add("Apple")
12 | $myList.Add("Banana")
13 | $myList.Add("Orange")
14 | $myList
15 | #>
16 | [CmdletBinding()]
17 | param()
18 | $List = [System.Collections.ArrayList]::new()
19 | <#
20 | Mathias R�rbo Jessen:
21 | The pipeline will attempt to unravel the list on assignment,
22 | so you'll have to either wrap the empty arraylist in an array,
23 | like above, or call WriteObject explicitly and tell it not to, like so:
24 | $PSCmdlet.WriteObject($List,$false)
25 | #>
26 | return , $List
27 | }
--------------------------------------------------------------------------------
/Private/Deprecated/Objects/New-GenericList.ps1:
--------------------------------------------------------------------------------
1 | function New-GenericList {
2 | <#
3 | .SYNOPSIS
4 | Creates a new instance of a generic list.
5 |
6 | .DESCRIPTION
7 | This function creates a new instance of a generic list based on the specified type.
8 |
9 | .PARAMETER Type
10 | Specifies the type of objects that the generic list will hold. Defaults to [System.Object].
11 |
12 | .EXAMPLE
13 | PS C:\> $list = New-GenericList -Type [int]
14 | Creates a new generic list that holds integers.
15 |
16 | .EXAMPLE
17 | PS C:\> $list = New-GenericList
18 | Creates a new generic list that holds objects.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | [Object] $Type = [System.Object]
24 | )
25 | return New-Object "System.Collections.Generic.List[$Type]"
26 | }
--------------------------------------------------------------------------------
/Private/Get-IPRange.ps1:
--------------------------------------------------------------------------------
1 | function Get-IPRange {
2 | <#
3 | .SYNOPSIS
4 | Generates a list of IP addresses within a specified binary range.
5 |
6 | .DESCRIPTION
7 | This function takes two binary strings representing the start and end IP addresses and generates a list of IP addresses within that range.
8 |
9 | .PARAMETER StartBinary
10 | Specifies the starting IP address in binary format.
11 |
12 | .PARAMETER EndBinary
13 | Specifies the ending IP address in binary format.
14 |
15 | .EXAMPLE
16 | Get-IPRange -StartBinary '11000000' -EndBinary '11000010'
17 | Description:
18 | Generates a list of IP addresses between '192.0.0.0' and '192.0.2.0'.
19 |
20 | .EXAMPLE
21 | Get-IPRange -StartBinary '10101010' -EndBinary '10101100'
22 | Description:
23 | Generates a list of IP addresses between '170.0.0.0' and '172.0.0.0'.
24 | #>
25 | [cmdletBinding()]
26 | param(
27 | [string] $StartBinary,
28 | [string] $EndBinary
29 | )
30 | [int64] $StartInt = [System.Convert]::ToInt64($StartBinary, 2)
31 | [int64] $EndInt = [System.Convert]::ToInt64($EndBinary, 2)
32 | for ($BinaryIP = $StartInt; $BinaryIP -le $EndInt; $BinaryIP++) {
33 | Convert-BinaryToIP ([System.Convert]::ToString($BinaryIP, 2).PadLeft(32, '0'))
34 | }
35 | }
--------------------------------------------------------------------------------
/Private/Get-LocalComputerSid.ps1:
--------------------------------------------------------------------------------
1 | function Get-LocalComputerSid {
2 | <#
3 | .SYNOPSIS
4 | Get the SID of the local computer.
5 |
6 | .DESCRIPTION
7 | Get the SID of the local computer.
8 |
9 | .EXAMPLE
10 | Get-LocalComputerSid
11 |
12 | .NOTES
13 | General notes
14 | #>
15 | [cmdletBinding()]
16 | param()
17 | try {
18 | Add-Type -AssemblyName System.DirectoryServices.AccountManagement
19 | $PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new([System.DirectoryServices.AccountManagement.ContextType]::Machine)
20 | $UserPrincipal = [System.DirectoryServices.AccountManagement.UserPrincipal]::new($PrincipalContext)
21 | $Searcher = [System.DirectoryServices.AccountManagement.PrincipalSearcher]::new()
22 | $Searcher.QueryFilter = $UserPrincipal
23 | $User = $Searcher.FindAll()
24 | foreach ($U in $User) {
25 | if ($U.Sid.Value -like "*-500") {
26 | return $U.Sid.Value.TrimEnd("-500")
27 | }
28 | }
29 | } catch {
30 | Write-Warning -Message "Get-LocalComputerSid - Error: $($_.Exception.Message)"
31 | }
32 | }
--------------------------------------------------------------------------------
/Private/Test-IPIsInNetwork.ps1:
--------------------------------------------------------------------------------
1 | function Test-IPIsInNetwork {
2 | <#
3 | .SYNOPSIS
4 | Checks if an IP address falls within a specified range defined by binary start and end values.
5 |
6 | .DESCRIPTION
7 | This function compares the binary representation of an IP address with the binary start and end values to determine if the IP address falls within the specified range.
8 |
9 | .EXAMPLE
10 | Test-IPIsInNetwork -IP "192.168.1.10" -StartBinary "11000000101010000000000100000000" -EndBinary "11000000101010000000000111111111"
11 |
12 | Description:
13 | Checks if the IP address 192.168.1.10 falls within the range defined by the binary start and end values.
14 |
15 | #>
16 | [cmdletBinding()]
17 | param(
18 | [string] $IP,
19 | [string] $StartBinary,
20 | [string] $EndBinary
21 | )
22 | $TestIPBinary = Convert-IPToBinary $IP
23 | [int64] $TestIPInt64 = [System.Convert]::ToInt64($TestIPBinary, 2)
24 | [int64] $StartInt64 = [System.Convert]::ToInt64($StartBinary, 2)
25 | [int64] $EndInt64 = [System.Convert]::ToInt64($EndBinary, 2)
26 | if ($TestIPInt64 -ge $StartInt64 -and $TestIPInt64 -le $EndInt64) {
27 | return $True
28 | } else {
29 | return $False
30 | }
31 | }
--------------------------------------------------------------------------------
/Private/Unregister-MountedRegistry.ps1:
--------------------------------------------------------------------------------
1 | function Unregister-MountedRegistry {
2 | <#
3 | .SYNOPSIS
4 | Unregisters mounted registry paths.
5 |
6 | .DESCRIPTION
7 | This function unregisters mounted registry paths that were previously mounted using Mount-PSRegistryPath.
8 |
9 | .EXAMPLE
10 | Unregister-MountedRegistry
11 |
12 | Description:
13 | Unregisters all mounted registry paths.
14 |
15 | #>
16 | [CmdletBinding()]
17 | param(
18 |
19 | )
20 | if ($null -ne $Script:DefaultRegistryMounted) {
21 | Write-Verbose -Message "Unregister-MountedRegistry - Dismounting HKEY_USERS\.DEFAULT_USER"
22 | $null = Dismount-PSRegistryPath -MountPoint "HKEY_USERS\.DEFAULT_USER"
23 | $Script:DefaultRegistryMounted = $null
24 | }
25 | if ($null -ne $Script:OfflineRegistryMounted) {
26 | foreach ($Key in $Script:OfflineRegistryMounted.Keys) {
27 | if ($Script:OfflineRegistryMounted[$Key].Status -eq $true) {
28 | Write-Verbose -Message "Unregister-MountedRegistry - Dismounting HKEY_USERS\$Key"
29 | $null = Dismount-PSRegistryPath -MountPoint "HKEY_USERS\$Key"
30 | }
31 | }
32 | $Script:OfflineRegistryMounted = $null
33 | }
34 | }
--------------------------------------------------------------------------------
/Public/Computers/Get-ComputerCulture.ps1:
--------------------------------------------------------------------------------
1 | function Get-ComputerCulture {
2 | <#
3 | .SYNOPSIS
4 | Retrieves culture information from a specified computer.
5 |
6 | .DESCRIPTION
7 | This function retrieves culture information from the specified computer. It provides details such as KeyboardLayoutId, DisplayName, and Windows Language.
8 |
9 | .PARAMETER ComputerName
10 | Specifies the name of the computer from which to retrieve culture information. Defaults to the local computer.
11 |
12 | .EXAMPLE
13 | Get-ComputerCulture
14 | Retrieves culture information from the local computer.
15 |
16 | .EXAMPLE
17 | Get-ComputerCulture -ComputerName "Server01"
18 | Retrieves culture information from a remote computer named Server01.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | [string] $ComputerName = $Env:COMPUTERNAME
24 | )
25 | $ScriptBlock = {
26 | Get-Culture | Select-Object KeyboardLayoutId, DisplayName, @{Expression = { $_.ThreeLetterWindowsLanguageName }; Label = "Windows Language" }
27 | }
28 | if ($ComputerName -eq $Env:COMPUTERNAME) {
29 | $Data8 = Invoke-Command -ScriptBlock $ScriptBlock
30 | } else {
31 | $Data8 = Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock
32 | }
33 | return $Data8
34 | }
--------------------------------------------------------------------------------
/Public/Computers/Get-ComputerMissingDrivers.ps1:
--------------------------------------------------------------------------------
1 | function Get-ComputerMissingDrivers {
2 | <#
3 | .SYNOPSIS
4 | Retrieves information about missing drivers on a specified computer.
5 |
6 | .DESCRIPTION
7 | This function retrieves information about missing drivers on a specified computer by querying the Win32_PNPEntity WMI class.
8 |
9 | .PARAMETER ComputerName
10 | Specifies the name of the computer to query. Defaults to the local computer.
11 |
12 | .EXAMPLE
13 | Get-ComputerMissingDrivers -ComputerName "Computer01"
14 | Retrieves information about missing drivers on a computer named "Computer01".
15 |
16 | .EXAMPLE
17 | Get-ComputerMissingDrivers
18 | Retrieves information about missing drivers on the local computer.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | [string] $ComputerName = $Env:COMPUTERNAME
24 | )
25 | $Data = Get-WmiObject Win32_PNPEntity -ComputerName $ComputerName | Where-Object {$_.Configmanagererrorcode -ne 0} | Select-Object Caption, ConfigmanagererrorCode, Description, DeviceId, HardwareId, PNPDeviceID
26 | return $Data
27 | }
28 |
--------------------------------------------------------------------------------
/Public/Computers/Get-ComputerOEMInformation.ps1:
--------------------------------------------------------------------------------
1 | function Get-ComputerOemInformation {
2 | <#
3 | .SYNOPSIS
4 | Retrieves OEM information from a specified computer.
5 |
6 | .DESCRIPTION
7 | This function retrieves OEM information such as Model, Manufacturer, Logo, Support Phone, Support URL, and Support Hours from the specified computer.
8 |
9 | .PARAMETER ComputerName
10 | Specifies the name of the computer from which to retrieve the OEM information. If not specified, the local computer name is used.
11 |
12 | .EXAMPLE
13 | Get-ComputerOemInformation
14 | Retrieves OEM information from the local computer.
15 |
16 | .EXAMPLE
17 | Get-ComputerOemInformation -ComputerName "Computer01"
18 | Retrieves OEM information from a remote computer named "Computer01".
19 |
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | [string] $ComputerName = $Env:COMPUTERNAME
24 | )
25 | $ScriptBlock = { Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation | Select-Object Model, Manufacturer, Logo, SupportPhone, SupportURL, SupportHours }
26 | if ($ComputerName -eq $Env:COMPUTERNAME) {
27 | $Data = Invoke-Command -ScriptBlock $ScriptBlock
28 | } else {
29 | $Data = Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock
30 | }
31 | return $Data
32 | }
--------------------------------------------------------------------------------
/Public/Computers/Get-ComputerServices.ps1:
--------------------------------------------------------------------------------
1 | function Get-ComputerService {
2 | <#
3 | .SYNOPSIS
4 | Retrieves information about services running on specified computers.
5 |
6 | .DESCRIPTION
7 | This function retrieves information about services running on one or more specified computers. It returns details such as ComputerName, Name, Displayname, Status, and StartType of the services.
8 |
9 | .EXAMPLE
10 | Get-ComputerServices -ComputerName "Computer01"
11 | Retrieves information about services running on a single computer named "Computer01".
12 |
13 | .EXAMPLE
14 | Get-ComputerServices -ComputerName "Computer01", "Computer02"
15 | Retrieves information about services running on multiple computers named "Computer01" and "Computer02".
16 |
17 | #>
18 | [alias('Get-ComputerServices')]
19 | [CmdletBinding()]
20 | param(
21 | [string[]] $ComputerName = $Env:COMPUTERNAME
22 | )
23 | Process {
24 | foreach ($Computer in $ComputerName) {
25 | $Services = Get-PSService -ComputerName $Computer | Select-Object ComputerName, Name, Displayname, Status, StartType
26 | $Services
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/Public/Connectivity/Get-IPAddressInformation.ps1:
--------------------------------------------------------------------------------
1 | function Get-IPAddressInformation {
2 | <#
3 | .SYNOPSIS
4 | Retrieves detailed information about an IP address using the ip-api.com service.
5 |
6 | .DESCRIPTION
7 | This function retrieves detailed information about the specified IP address using the ip-api.com service. It provides details such as country, region, city, ISP, and more.
8 |
9 | .PARAMETER IP
10 | Specifies the IP address for which information needs to be retrieved.
11 |
12 | .EXAMPLE
13 | Get-IpAddressInformation -IP "8.8.8.8"
14 | Retrieves information about the IP address "8.8.8.8" using the ip-api.com service.
15 |
16 | .NOTES
17 | This function requires an active internet connection to retrieve IP address information from the ip-api.com service.
18 | #>
19 | [cmdletbinding()]
20 | param(
21 | [string] $IP
22 | )
23 | try {
24 | $Information = Invoke-RestMethod -Method get -Uri "http://ip-api.com/json/$ip"
25 | } catch {
26 | $ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " "
27 | Write-Warning "Get-IPAddressInformation - Error occured on IP $IP`: $ErrorMessage"
28 | }
29 | return $Information
30 | }
--------------------------------------------------------------------------------
/Public/Connectivity/Get-MyIpAddress.ps1:
--------------------------------------------------------------------------------
1 | function Get-MyIpAddress {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the public IP address of the current machine using OpenDNS.
5 |
6 | .DESCRIPTION
7 | This function retrieves the public IP address of the current machine by querying OpenDNS servers. It returns the IP address as a string.
8 |
9 | .EXAMPLE
10 | Get-MyIpAddress
11 | Retrieves the public IP address of the current machine.
12 |
13 | .NOTES
14 | Author: Your Name
15 | Date: Current Date
16 | #>
17 | [alias('Get-MyIP')]
18 | [CmdletBinding()]
19 | param()
20 | $DNSParam = @{
21 | Name = 'myip.opendns.com'
22 | Server = 'resolver1.opendns.com'
23 | DnsOnly = $true
24 | }
25 | return Resolve-DnsName @DNSParam | ForEach-Object IPAddress
26 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-BinaryToHex.ps1:
--------------------------------------------------------------------------------
1 | function Convert-BinaryToHex {
2 | <#
3 | .SYNOPSIS
4 | Converts an array of binary numbers to hexadecimal format.
5 |
6 | .DESCRIPTION
7 | This function takes an array of binary numbers and converts them to hexadecimal format.
8 |
9 | .PARAMETER Binary
10 | Specifies the array of binary numbers to be converted to hexadecimal.
11 |
12 | .EXAMPLE
13 | Convert-BinaryToHex -Binary 1101 1010
14 | Converts the binary numbers 1101 and 1010 to hexadecimal format.
15 |
16 | .EXAMPLE
17 | 1101 1010 | Convert-BinaryToHex
18 | Converts the binary numbers 1101 and 1010 piped into the function to hexadecimal format.
19 | #>
20 | param(
21 | [alias('Bin')]
22 | [Parameter(Position = 0, Mandatory = $false, ValueFromPipeline = $true)]
23 | [Byte[]]$Binary
24 | )
25 | if ($null -eq $Binary) {
26 | return
27 | }
28 | # assume pipeline input if we don't have an array (surely there must be a better way)
29 | if ($Binary.Length -eq 1) {
30 | $Binary = @($input)
31 | }
32 | $Return = -join ($Binary | ForEach-Object { "{0:X2}" -f $_ })
33 | $Return
34 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-BinaryToString.ps1:
--------------------------------------------------------------------------------
1 | function Convert-BinaryToString {
2 | <#
3 | .SYNOPSIS
4 | Converts an array of binary numbers to a string.
5 |
6 | .DESCRIPTION
7 | This function takes an array of binary numbers and converts them to a string using Unicode encoding.
8 |
9 | .PARAMETER Binary
10 | Specifies the array of binary numbers to be converted to a string.
11 |
12 | .EXAMPLE
13 | Convert-BinaryToString -Binary 01001000 01100101 01101100 01101100 01101111
14 | Converts the binary numbers to the string "Hello".
15 |
16 | .EXAMPLE
17 | 01001000 01100101 01101100 01101100 01101111 | Convert-BinaryToString
18 | Converts the binary numbers piped into the function to the string "Hello".
19 | #>
20 | param(
21 | [alias('Bin')]
22 | [Parameter(Position = 0, Mandatory = $false, ValueFromPipeline = $true)]
23 | [Byte[]]$Binary
24 | )
25 | if ($null -ne $Binary) {
26 | [System.Text.Encoding]::Unicode.GetString($Binary)
27 | }
28 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-DomainToSid.ps1:
--------------------------------------------------------------------------------
1 | function Convert-DomainToSid {
2 | <#
3 | .SYNOPSIS
4 | Converts Domain Name to SID
5 |
6 | .DESCRIPTION
7 | Converts Domain Name to SID
8 |
9 | .PARAMETER DomainName
10 | DomainName for current forest or trusted forest
11 |
12 | .EXAMPLE
13 | Convert-DomainToSid -DomainName 'test.evotec.pl'
14 |
15 | .NOTES
16 | General notes
17 | #>
18 | [cmdletBinding()]
19 | param(
20 | [parameter(Mandatory)][string] $DomainName
21 | )
22 | try {
23 | $BinarySID = ([ADSI]"LDAP://$DomainName").objectsid
24 | $DomainSidValue = [System.Security.Principal.SecurityIdentifier]::new($BinarySID.Value, 0).Value
25 | $DomainSidValue
26 | } catch {
27 | Write-Warning -Message "Convert-DomainToSid - Failed conversion with error $($_.Exception.Message)"
28 | }
29 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-ExchangeItems.ps1:
--------------------------------------------------------------------------------
1 | function Convert-ExchangeItems {
2 | <#
3 | .SYNOPSIS
4 | Converts the count of Exchange items to a specified default value if the count is null.
5 |
6 | .DESCRIPTION
7 | This function takes the count of Exchange items and returns the count if it is not null. If the count is null, it returns the specified default value.
8 |
9 | .PARAMETER Count
10 | The count of Exchange items to be processed.
11 |
12 | .PARAMETER Default
13 | The default value to return if the count is null. Default is 'N/A'.
14 |
15 | .EXAMPLE
16 | Convert-ExchangeItems -Count 10 -Default 'No items'
17 | # Returns 10
18 |
19 | .EXAMPLE
20 | Convert-ExchangeItems -Count $null -Default 'No items'
21 | # Returns 'No items'
22 |
23 | .NOTES
24 | General notes
25 | #>
26 | [cmdletbinding()]
27 | param(
28 | [int] $Count,
29 | [string] $Default = 'N/A'
30 | )
31 | if ($null -eq $Count) {
32 | return $Default
33 | } else {
34 | return $Count
35 | }
36 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-HexToBinary.ps1:
--------------------------------------------------------------------------------
1 | function Convert-HexToBinary {
2 | <#
3 | .SYNOPSIS
4 | Converts a hexadecimal string to a binary representation.
5 |
6 | .DESCRIPTION
7 | This function takes a hexadecimal string as input and converts it to a binary representation.
8 |
9 | .PARAMETER Hex
10 | Specifies the hexadecimal string to convert to binary.
11 |
12 | .EXAMPLE
13 | Convert-HexToBinary -Hex "1A"
14 | # Outputs: 00011010
15 |
16 | .EXAMPLE
17 | "1A" | Convert-HexToBinary
18 | # Outputs: 00011010
19 | #>
20 | [CmdletBinding()]
21 | param(
22 | [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [string] $Hex
23 | )
24 | $return = for ($i = 0; $i -lt $Hex.Length ; $i += 2) {
25 | [Byte]::Parse($Hex.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber)
26 | }
27 | Write-Output $return -NoEnumerate
28 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-IPAddressToPTR.ps1:
--------------------------------------------------------------------------------
1 | function Convert-IpAddressToPtr {
2 | <#
3 | .SYNOPSIS
4 | Converts an IP address to a PTR record
5 |
6 | .DESCRIPTION
7 | This function takes an IP address as input and converts it to a PTR record.
8 |
9 | .PARAMETER IPAddress
10 | The IP address to convert
11 |
12 | .PARAMETER AsObject
13 | Should the function return an object instead of a string?
14 |
15 | .EXAMPLE
16 | Convert-IpAddressToPtr -IPAddress "10.1.2.3"
17 |
18 | .EXAMPLE
19 | Convert-IpAddressToPtr -IPAddress "10.1.2.3", "8.8.8.8" -AsObject
20 |
21 | .NOTES
22 | General notes
23 | #>
24 | [CmdletBinding()]
25 | param (
26 | [Parameter(Mandatory = $true)]
27 | [string[]]$IPAddress,
28 | [switch] $AsObject
29 | )
30 | foreach ($IP in $IPAddress) {
31 |
32 | # Split the IP address into its octets
33 | $octets = $IP -split "\."
34 |
35 | # Reverse the octets
36 | [array]::Reverse($octets)
37 |
38 | # Join the reversed octets with dots and append the standard PTR suffix
39 | $ptrString = ($octets -join ".") + ".in-addr.arpa"
40 |
41 | if ($AsObject) {
42 | [pscustomobject] @{
43 | IPAddress = $IP
44 | PTR = $ptrString
45 | }
46 | } else {
47 | $ptrString
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-KeyToValue.ps1:
--------------------------------------------------------------------------------
1 | function Convert-KeyToKeyValue {
2 | <#
3 | .SYNOPSIS
4 | Converts keys of an object to key-value pairs.
5 |
6 | .DESCRIPTION
7 | This function takes an object and converts its keys to key-value pairs, where the key is the original key concatenated with its corresponding value.
8 |
9 | .PARAMETER Object
10 | Specifies the object whose keys are to be converted to key-value pairs.
11 |
12 | .EXAMPLE
13 | $Object = @{
14 | Key1 = 'Value1'
15 | Key2 = 'Value2'
16 | }
17 | Convert-KeyToKeyValue -Object $Object
18 | # Returns a new hash table with keys as 'Key1 (Value1)' and 'Key2 (Value2)'.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param (
23 | [object] $Object
24 | )
25 | $NewHash = [ordered] @{}
26 | foreach ($O in $Object.Keys) {
27 | $KeyName = "$O ($($Object.$O))"
28 | $KeyValue = $Object.$O
29 | $NewHash.$KeyName = $KeyValue
30 | }
31 | return $NewHash
32 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-ToDateTime.ps1:
--------------------------------------------------------------------------------
1 | function Convert-ToDateTime {
2 | <#
3 | .SYNOPSIS
4 | Converts a file time string to a DateTime object.
5 |
6 | .DESCRIPTION
7 | This function converts a file time string to a DateTime object. It handles the conversion and provides flexibility to ignore specific file time strings.
8 |
9 | .PARAMETER Timestring
10 | Specifies the file time string to convert to a DateTime object.
11 |
12 | .PARAMETER Ignore
13 | Specifies a pattern to ignore specific file time strings. Default is '*1601*'.
14 |
15 | .EXAMPLE
16 | Convert-ToDateTime -Timestring '132479040000000000'
17 | # Converts the file time string '132479040000000000' to a DateTime object.
18 |
19 | .EXAMPLE
20 | Convert-ToDateTime -Timestring '132479040000000000' -Ignore '*1601*'
21 | # Converts the file time string '132479040000000000' to a DateTime object, ignoring any file time strings containing '1601'.
22 |
23 | #>
24 | [CmdletBinding()]
25 | param (
26 | [string] $Timestring,
27 | [string] $Ignore = '*1601*'
28 | )
29 | Try {
30 | $DateTime = ([datetime]::FromFileTime($Timestring))
31 | } catch {
32 | $DateTime = $null
33 | }
34 | if ($null -eq $DateTime -or $Timestring -like $Ignore) {
35 | return $null
36 | } else {
37 | return $DateTime
38 | }
39 | }
--------------------------------------------------------------------------------
/Public/Converts/Convert-ToTimeSpan.ps1:
--------------------------------------------------------------------------------
1 | function Convert-ToTimeSpan {
2 | <#
3 | .SYNOPSIS
4 | Calculates the time span between two given DateTime values.
5 |
6 | .DESCRIPTION
7 | This function calculates the time span between two specified DateTime values. It takes a start time and an end time as input parameters and returns the TimeSpan object representing the duration between them.
8 |
9 | .PARAMETER StartTime
10 | Specifies the start DateTime value. If not provided, the current date and time will be used as the default.
11 |
12 | .PARAMETER EndTime
13 | Specifies the end DateTime value.
14 |
15 | .EXAMPLE
16 | Convert-ToTimeSpan -StartTime (Get-Date).AddDays(-5) -EndTime (Get-Date)
17 | # Calculates the time span between 5 days ago and today.
18 |
19 | .EXAMPLE
20 | Convert-ToTimeSpan -StartTime '2022-01-01' -EndTime '2022-01-10'
21 | # Calculates the time span between January 1, 2022, and January 10, 2022.
22 |
23 | #>
24 | [CmdletBinding()]
25 | param (
26 | [DateTime] $StartTime = (Get-Date),
27 | [DateTime] $EndTime
28 | )
29 | if ($StartTime -and $EndTime) {
30 | try {
31 | $TimeSpan = (New-TimeSpan -Start $StartTime -End $EndTime)
32 | } catch {
33 | $TimeSpan = $null
34 | }
35 | }
36 | if ($null -ne $TimeSpan) {
37 | return $TimeSpan
38 | } else {
39 | return $null
40 | }
41 | }
--------------------------------------------------------------------------------
/Public/Converts/ConvertFrom-OperationType.ps1:
--------------------------------------------------------------------------------
1 | Function ConvertFrom-OperationType {
2 | <#
3 | .SYNOPSIS
4 | Converts operation type codes to human-readable descriptions.
5 |
6 | .DESCRIPTION
7 | This function takes an operation type code and returns the corresponding human-readable description.
8 |
9 | .PARAMETER OperationType
10 | The operation type code to be converted.
11 |
12 | .EXAMPLE
13 | ConvertFrom-OperationType -OperationType '%%14674'
14 | Output: 'Value Added'
15 |
16 | .EXAMPLE
17 | ConvertFrom-OperationType -OperationType '%%14675'
18 | Output: 'Value Deleted'
19 |
20 | .EXAMPLE
21 | ConvertFrom-OperationType -OperationType '%%14676'
22 | Output: 'Unknown'
23 | #>
24 | param (
25 | [string] $OperationType
26 | )
27 | $Known = @{
28 | '%%14674' = 'Value Added'
29 | '%%14675' = 'Value Deleted'
30 | '%%14676' = 'Unknown'
31 | }
32 | foreach ($id in $OperationType) {
33 | if ($name = $Known[$id]) { return $name }
34 | }
35 | return $OperationType
36 | }
--------------------------------------------------------------------------------
/Public/Converts/ConvertFrom-ScriptBlock.ps1:
--------------------------------------------------------------------------------
1 | function ConvertFrom-ScriptBlock {
2 | <#
3 | .SYNOPSIS
4 | Converts a ScriptBlock into an array of strings, each representing a line of the script block.
5 |
6 | .DESCRIPTION
7 | This function takes a ScriptBlock as input and converts it into an array of strings, where each string represents a line of the script block.
8 |
9 | .PARAMETER ScriptBlock
10 | The ScriptBlock to be converted into an array of strings.
11 |
12 | .EXAMPLE
13 | ConvertFrom-ScriptBlock -ScriptBlock {
14 | $Variable1 = "Value1"
15 | $Variable2 = "Value2"
16 | Write-Host "Hello, World!"
17 | }
18 |
19 | This example will output an array containing the following strings:
20 | $Variable1 = "Value1"
21 | $Variable2 = "Value2"
22 | Write-Host "Hello, World!"
23 |
24 | .NOTES
25 | General notes
26 | #>
27 | [CmdletBinding()]
28 | param(
29 | [ScriptBlock] $ScriptBlock
30 | )
31 | [Array] $Output = foreach ($Line in $ScriptBlock.Ast.EndBlock.Statements.Extent) {
32 | [string] $Line + [System.Environment]::NewLine
33 | }
34 | return $Output
35 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-FileInformation.ps1:
--------------------------------------------------------------------------------
1 | function Get-FileInformation {
2 | <#
3 | .SYNOPSIS
4 | Get information about file such as Name, FullName and Size
5 |
6 | .DESCRIPTION
7 | Get information about file such as Name, FullName and Size
8 |
9 | .PARAMETER File
10 | File to get information about
11 |
12 | .EXAMPLE
13 | Get-FileInformation -File 'C:\Support\GitHub\PSSharedGoods\Public\FilesFolders\Get-FileInformation.ps1'
14 |
15 | #>
16 | [CmdletBinding()]
17 | param(
18 | [alias('LiteralPath', 'Path')][string] $File
19 | )
20 | if (Test-Path -LiteralPath $File) {
21 | $Item = Get-Item -LiteralPath $File
22 | [PSCustomObject] @{
23 | Name = $Item.Name
24 | FullName = $Item.FullName
25 | Size = Get-FileSize -Bytes $Item.Length
26 | IsReadOnly = $Item.IsReadOnly
27 | LastWriteTime = $Item.LastWriteTime
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-FileSize.ps1:
--------------------------------------------------------------------------------
1 | function Get-FileSize {
2 | <#
3 | .SYNOPSIS
4 | Get-FileSize function calculates the file size in human-readable format.
5 |
6 | .DESCRIPTION
7 | This function takes a file size in bytes and converts it into a human-readable format (e.g., KB, MB, GB, etc.).
8 |
9 | .PARAMETER Bytes
10 | Specifies the size of the file in bytes.
11 |
12 | .EXAMPLE
13 | Get-FileSize -Bytes 1024
14 | Output: 1 KB
15 |
16 | .EXAMPLE
17 | Get-FileSize -Bytes 1048576
18 | Output: 1 MB
19 | #>
20 | [CmdletBinding()]
21 | param(
22 | $Bytes
23 | )
24 | $sizes = 'Bytes,KB,MB,GB,TB,PB,EB,ZB' -split ','
25 | for ($i = 0; ($Bytes -ge 1kb) -and ($i -lt $sizes.Count); $i++) {
26 | $Bytes /= 1kb
27 | }
28 | $N = 2;
29 | if ($i -eq 0) {
30 | $N = 0
31 | }
32 | return "{0:N$($N)} {1}" -f $Bytes, $sizes[$i]
33 | }
34 |
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-FilesInFolder.ps1:
--------------------------------------------------------------------------------
1 | function Get-FilesInFolder {
2 | <#
3 | .SYNOPSIS
4 | Retrieves a list of files in a specified folder with the option to filter by extension.
5 |
6 | .DESCRIPTION
7 | This function retrieves a list of files in the specified folder. By default, it includes all files with the '.evtx' extension, but you can specify a different extension using the $Extension parameter.
8 |
9 | .PARAMETER Folder
10 | Specifies the folder path from which to retrieve files.
11 |
12 | .PARAMETER Extension
13 | Specifies the file extension to filter by. Default value is '*.evtx'.
14 |
15 | .EXAMPLE
16 | Get-FilesInFolder -Folder "C:\Logs"
17 |
18 | Description:
19 | Retrieves all files with the '.evtx' extension in the "C:\Logs" folder.
20 |
21 | .EXAMPLE
22 | Get-FilesInFolder -Folder "D:\Documents" -Extension '*.txt'
23 |
24 | Description:
25 | Retrieves all files with the '.txt' extension in the "D:\Documents" folder.
26 |
27 | #>
28 | [CmdletBinding()]
29 | param(
30 | [string] $Folder,
31 | [string] $Extension = '*.evtx'
32 | )
33 |
34 | $Files = Get-ChildItem -Path $Folder -Filter $Extension -Recurse
35 | $ReturnFiles = foreach ($File in $Files) {
36 | $File.FullName
37 | }
38 | return $ReturnFiles
39 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-PathSeparator.ps1:
--------------------------------------------------------------------------------
1 | function Get-PathSeparator {
2 | <#
3 | .SYNOPSIS
4 | Gets the path separator character used by the operating system.
5 |
6 | .DESCRIPTION
7 | This function retrieves the path separator character used by the operating system. It can be useful for handling file paths in a platform-independent manner.
8 |
9 | .EXAMPLE
10 | Get-PathSeparator
11 | Output:
12 | \
13 |
14 | .NOTES
15 | The function uses [System.IO.Path]::PathSeparator to get the path separator character.
16 | #>
17 | [CmdletBinding()]
18 | param()
19 | return [IO.Path]::PathSeparator
20 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-PathTemporary.ps1:
--------------------------------------------------------------------------------
1 | function Get-PathTemporary {
2 | <#
3 | .SYNOPSIS
4 | Gets the path to the temporary directory.
5 |
6 | .DESCRIPTION
7 | This function retrieves the path to the system's temporary directory.
8 |
9 | .EXAMPLE
10 | Get-PathTemporary
11 | Output:
12 | C:\Users\Username\AppData\Local\Temp
13 |
14 | .NOTES
15 | The function uses [System.IO.Path]::GetTempPath() to get the temporary directory path.
16 | #>
17 | [CmdletBinding()]
18 | param()
19 | return [IO.path]::GetTempPath()
20 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Get-TemporaryDirectory.ps1:
--------------------------------------------------------------------------------
1 | function Get-TemporaryDirectory {
2 | <#
3 | .SYNOPSIS
4 | Creates a temporary directory and returns its path.
5 |
6 | .DESCRIPTION
7 | This function generates a temporary directory with a unique name and returns the full path to the directory.
8 |
9 | .EXAMPLE
10 | $tempDir = Get-TemporaryDirectory
11 | $tempDir
12 | Output:
13 | C:\Users\Username\AppData\Local\Temp\abcde12345
14 |
15 | .NOTES
16 | The temporary directory is created using a random string name with specified characteristics.
17 | #>
18 | param(
19 |
20 | )
21 | $TemporaryFolder = Get-RandomStringName -Size 13 -LettersOnly -ToLower
22 | $TemporaryPath = [system.io.path]::GetTempPath()
23 | $Output = New-Item -ItemType Directory -Path $TemporaryPath -Name $TemporaryFolder -Force
24 | if (Test-Path -LiteralPath $Output.FullName) {
25 | $Output
26 | }
27 | }
--------------------------------------------------------------------------------
/Public/FilesFolders/Set-FileInheritance.ps1:
--------------------------------------------------------------------------------
1 | function Set-FileInheritance {
2 | <#
3 | .SYNOPSIS
4 | Sets or removes inheritance for a specified directory.
5 |
6 | .DESCRIPTION
7 | This function allows you to set or remove inheritance for a specified directory. You can choose to disable inheritance and optionally keep the inherited ACL.
8 |
9 | .PARAMETER StartingDir
10 | Specifies the directory for which to set or remove inheritance.
11 |
12 | .PARAMETER DisableInheritance
13 | Switch parameter to disable inheritance for the specified directory.
14 |
15 | .PARAMETER KeepInheritedAcl
16 | Switch parameter to keep the inherited ACL when disabling inheritance.
17 |
18 | .EXAMPLE
19 | Set-FileInheritance -StartingDir "C:\Example" -DisableInheritance
20 | Disables inheritance for the directory "C:\Example".
21 |
22 | .EXAMPLE
23 | Set-FileInheritance -StartingDir "D:\Data" -DisableInheritance -KeepInheritedAcl
24 | Disables inheritance for the directory "D:\Data" and keeps the inherited ACL.
25 |
26 | #>
27 | [cmdletBinding()]
28 | param(
29 | [string] $StartingDir,
30 | [switch] $DisableInheritance,
31 | [switch] $KeepInheritedAcl
32 | )
33 | $acl = Get-Acl -Path $StartingDir
34 | $acl.SetAccessRuleProtection($DisableInheritance, $KeepInheritedAcl)
35 | $acl | Set-Acl -Path $StartingDir
36 | }
--------------------------------------------------------------------------------
/Public/Objects/Copy-Dictionary.ps1:
--------------------------------------------------------------------------------
1 | function Copy-Dictionary {
2 | <#
3 | .SYNOPSIS
4 | Copies dictionary/hashtable
5 |
6 | .DESCRIPTION
7 | Copies dictionary uusing PS Serializer. Replaces usage of BinnaryFormatter due to no support in PS 7.4
8 |
9 | .PARAMETER Dictionary
10 | Dictionary to copy
11 |
12 | .EXAMPLE
13 | $Test = [ordered] @{
14 | Test = 'Test'
15 | Test1 = @{
16 | Test2 = 'Test2'
17 | Test3 = @{
18 | Test4 = 'Test4'
19 | }
20 | }
21 | Test2 = @(
22 | "1", "2", "3"
23 | )
24 | Test3 = [PSCustomObject] @{
25 | Test4 = 'Test4'
26 | Test5 = 'Test5'
27 | }
28 | }
29 |
30 | $New1 = Copy-Dictionary -Dictionary $Test
31 | $New1
32 |
33 | .NOTES
34 |
35 | #>
36 | [alias('Copy-Hashtable', 'Copy-OrderedHashtable')]
37 | [cmdletbinding()]
38 | param(
39 | [System.Collections.IDictionary] $Dictionary
40 | )
41 | $clone = [System.Management.Automation.PSSerializer]::Serialize($Dictionary, [int32]::MaxValue)
42 | return [System.Management.Automation.PSSerializer]::Deserialize($clone)
43 | }
--------------------------------------------------------------------------------
/Public/Objects/Format-FirstXChars.ps1:
--------------------------------------------------------------------------------
1 | function Format-FirstXChars {
2 | <#
3 | .SYNOPSIS
4 | This function returns the first X characters of a given text string.
5 |
6 | .DESCRIPTION
7 | The Format-FirstXChars function takes a text string and a number of characters as input and returns the first X characters of the text string.
8 |
9 | .PARAMETER Text
10 | The input text string from which the first X characters will be extracted.
11 |
12 | .PARAMETER NumberChars
13 | The number of characters to extract from the beginning of the input text string.
14 |
15 | .EXAMPLE
16 | Format-FirstXChars -Text "VERBOSE: Loading module from path 'C:\Users\pklys\.vscode\extensions\ms-vs" -NumberChars 15
17 | # Returns: VERBOSE: Loading
18 |
19 | .NOTES
20 | This function is useful for truncating long text strings to a specific length.
21 | #>
22 | param(
23 | [string] $Text,
24 | [int] $NumberChars
25 | )
26 | return ($Text.ToCharArray() | Select-Object -First $NumberChars) -join ''
27 | }
--------------------------------------------------------------------------------
/Public/Objects/Get-Colors.ps1:
--------------------------------------------------------------------------------
1 | function Get-Colors {
2 | <#
3 | .SYNOPSIS
4 | Retrieves RGB color values based on the provided color names.
5 |
6 | .DESCRIPTION
7 | The Get-Colors function retrieves RGB color values from a predefined list based on the color names provided as input. If no color names are specified, it returns all available RGB color values.
8 |
9 | .PARAMETER Color
10 | Specifies an array of color names for which RGB values are to be retrieved.
11 |
12 | .EXAMPLE
13 | Get-Colors -Color "Red", "Green"
14 | Retrieves the RGB values for the colors Red and Green.
15 |
16 | .EXAMPLE
17 | Get-Colors
18 | Retrieves all available RGB color values.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param(
23 | [string[]] $Color
24 | )
25 | if ($Color) {
26 | foreach ($_ in $Color) {
27 | $Script:RGBColors.$_
28 | }
29 | } else {
30 | return $Script:RGBColors
31 | }
32 | }
33 | $ScriptBlockColors = {
34 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
35 | $Script:RGBColors.Keys | Where-Object { $_ -like "*$wordToComplete*" }
36 | }
37 |
38 | Register-ArgumentCompleter -CommandName Get-Colors -ParameterName Color -ScriptBlock $ScriptBlockColors
--------------------------------------------------------------------------------
/Public/Objects/Get-MimeType.ps1:
--------------------------------------------------------------------------------
1 | function Get-MimeType {
2 | <#
3 | .SYNOPSIS
4 | Get-MimeType function returns the MIME type of a file based on its extension.
5 |
6 | .DESCRIPTION
7 | This function takes a file name as input and returns the corresponding MIME type based on the file extension.
8 |
9 | .PARAMETER FileName
10 | Specifies the name of the file for which the MIME type needs to be determined.
11 |
12 | .EXAMPLE
13 | Get-MimeType -FileName "example.jpg"
14 | Returns "image/jpeg" as the MIME type for the file "example.jpg".
15 |
16 | .EXAMPLE
17 | Get-MimeType -FileName "example.png"
18 | Returns "image/png" as the MIME type for the file "example.png".
19 | #>
20 | [CmdletBinding()]
21 | param (
22 | [Parameter(Mandatory = $true)]
23 | [string] $FileName
24 | )
25 |
26 | $MimeMappings = @{
27 | '.jpeg' = 'image/jpeg'
28 | '.jpg' = 'image/jpeg'
29 | '.png' = 'image/png'
30 | }
31 |
32 | $Extension = [System.IO.Path]::GetExtension( $FileName )
33 | $ContentType = $MimeMappings[ $Extension ]
34 |
35 | if ([string]::IsNullOrEmpty($ContentType)) {
36 | return New-Object System.Net.Mime.ContentType
37 | } else {
38 | return New-Object System.Net.Mime.ContentType($ContentType)
39 | }
40 | }
--------------------------------------------------------------------------------
/Public/Objects/Get-Types.ps1:
--------------------------------------------------------------------------------
1 | Function Get-Types {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the enum values of the specified types.
5 |
6 | .DESCRIPTION
7 | This function takes an array of types and returns the enum values of each type.
8 |
9 | .PARAMETER Types
10 | Specifies the types for which enum values need to be retrieved.
11 |
12 | .EXAMPLE
13 | Get-Types -Types [System.DayOfWeek]
14 | Retrieves the enum values of the System.DayOfWeek type.
15 |
16 | .EXAMPLE
17 | Get-Types -Types [System.ConsoleColor, System.EnvironmentVariableTarget]
18 | Retrieves the enum values of the System.ConsoleColor and System.EnvironmentVariableTarget types.
19 | #>
20 | [CmdletBinding()]
21 | param (
22 | [Object] $Types
23 | )
24 | $TypesRequired = foreach ($Type in $Types) {
25 | $Type.GetEnumValues()
26 | }
27 | return $TypesRequired
28 | }
--------------------------------------------------------------------------------
/Public/Objects/Join-Uri.ps1:
--------------------------------------------------------------------------------
1 | function Join-Uri {
2 | <#
3 | .SYNOPSIS
4 | Provides ability to join two Url paths together
5 |
6 | .DESCRIPTION
7 | Provides ability to join two Url paths together
8 |
9 | .PARAMETER BaseUri
10 | Primary Url to merge
11 |
12 | .PARAMETER RelativeOrAbsoluteUri
13 | Additional path to merge with primary url
14 |
15 | .EXAMPLE
16 | Join-Uri 'https://evotec.xyz/' '/wp-json/wp/v2/posts'
17 |
18 | .EXAMPLE
19 | Join-Uri 'https://evotec.xyz/' 'wp-json/wp/v2/posts'
20 |
21 | .EXAMPLE
22 | Join-Uri -BaseUri 'https://evotec.xyz/' -RelativeOrAbsoluteUri '/wp-json/wp/v2/posts'
23 |
24 | .EXAMPLE
25 | Join-Uri -BaseUri 'https://evotec.xyz/test/' -RelativeOrAbsoluteUri '/wp-json/wp/v2/posts'
26 |
27 | .NOTES
28 | General notes
29 | #>
30 | [alias('Join-Url')]
31 | [cmdletBinding()]
32 | param(
33 | [parameter(Mandatory)][uri] $BaseUri,
34 | [parameter(Mandatory)][uri] $RelativeOrAbsoluteUri
35 | )
36 |
37 | return ($BaseUri.OriginalString.TrimEnd('/') + "/" + $RelativeOrAbsoluteUri.OriginalString.TrimStart('/'))
38 | #return [Uri]::new([Uri]::new($BaseUri), $RelativeOrAbsoluteUri).ToString()
39 | #return [Uri]::new($BaseUri.OriginalString, $RelativeOrAbsoluteUri).ToString()
40 | }
--------------------------------------------------------------------------------
/Public/Objects/Remove-WhiteSpace.ps1:
--------------------------------------------------------------------------------
1 | function Remove-WhiteSpace {
2 | <#
3 | .SYNOPSIS
4 | Removes leading, trailing, and extra white spaces from a given text string.
5 |
6 | .DESCRIPTION
7 | The Remove-WhiteSpace function removes any leading, trailing, and extra white spaces from the input text string. It ensures that only single spaces separate words within the text.
8 |
9 | .PARAMETER Text
10 | The input text string from which white spaces are to be removed.
11 |
12 | .EXAMPLE
13 | $MyValue = Remove-WhiteSpace -Text ' My Field '
14 | # $MyValue now contains 'My Field'
15 |
16 | #>
17 | param(
18 | [string] $Text
19 | )
20 | $Text = $Text -replace '(^\s+|\s+$)','' -replace '\s+',' '
21 | return $Text
22 | }
23 | <#
24 | $MyValue = Remove-WhiteSpace -Text 'My Field '
25 | Write-Color $MyValue, 'No' -Color White, Yellow
26 |
27 | #>
--------------------------------------------------------------------------------
/Public/Objects/Rename-LatinCharacters.ps1:
--------------------------------------------------------------------------------
1 | Function Rename-LatinCharacters {
2 | <#
3 | .SYNOPSIS
4 | Renames a name to a name without special chars.
5 |
6 | .DESCRIPTION
7 | Renames a name to a name without special chars.
8 |
9 | .PARAMETER String
10 | Provide a string to rename
11 |
12 | .EXAMPLE
13 | Rename-LatinCharacters -String 'Przemysław Kłys'
14 |
15 | .EXAMPLE
16 | Rename-LatinCharacters -String 'Przemysław'
17 |
18 | .NOTES
19 | General notes
20 | #>
21 | [alias('Remove-StringLatinCharacters')]
22 | [cmdletBinding()]
23 | param(
24 | [string] $String
25 | )
26 | [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($String))
27 | }
--------------------------------------------------------------------------------
/Public/Objects/Test-IsDistinguishedName.ps1:
--------------------------------------------------------------------------------
1 | function Test-IsDistinguishedName {
2 | <#
3 | .SYNOPSIS
4 | Determines whether a given string is a valid Distinguished Name (DN) format.
5 |
6 | .DESCRIPTION
7 | This function checks if the provided string matches the format of a Distinguished Name (DN) in Active Directory. It validates the structure of a DN which typically consists of Common Name (CN), Organizational Unit (OU), and Domain Component (DC) components.
8 |
9 | .PARAMETER Identity
10 | Specifies the string to be tested as a Distinguished Name (DN).
11 |
12 | .EXAMPLE
13 | Test-IsDistinguishedName -Identity "CN=John Doe,OU=Users,DC=example,DC=com"
14 | This example checks if the given string is a valid Distinguished Name format.
15 |
16 | .NOTES
17 | Original source: https://github.com/PsCustomObject/IT-ToolBox/blob/master/Public/Test-IsValidDn.ps1
18 |
19 | #>
20 | [alias('Test-IsDN')]
21 | [cmdletBinding()]
22 | param (
23 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
24 | [Alias('DN', 'DistinguishedName')][string] $Identity
25 | )
26 | Process {
27 | [regex]$distinguishedNameRegex = '^(?:(?CN=(?(?:[^,]|\,)*)),)?(?:(?(?:(?:CN|OU)=(?:[^,]|\,)+,?)+),)?(?(?:DC=(?:[^,]|\,)+,?)+)$'
28 | $Identity -match $distinguishedNameRegex
29 | }
30 | }
--------------------------------------------------------------------------------
/Public/Programs/Find-MyProgramData.ps1:
--------------------------------------------------------------------------------
1 | function Find-MyProgramData {
2 | <#
3 | .SYNOPSIS
4 | Finds specific data within a given array of strings.
5 |
6 | .DESCRIPTION
7 | This function searches for a specific text within an array of strings and returns the second element of the string that matches the search criteria.
8 |
9 | .PARAMETER Data
10 | The array of strings to search through.
11 |
12 | .PARAMETER FindText
13 | The text to search for within the array of strings.
14 |
15 | .EXAMPLE
16 | Find-MyProgramData -Data @("Program A 123", "Program B 456", "Program C 789") -FindText "B"
17 | This example will return "456" as it finds the string containing "B" and returns the second element of that string.
18 |
19 | #>
20 | [CmdletBinding()]
21 | param (
22 | $Data,
23 | $FindText
24 | )
25 | foreach ($Sub in $Data) {
26 | if ($Sub -like $FindText) {
27 | $Split = $Sub.Split(' ')
28 | return $Split[1]
29 | }
30 | }
31 | return ''
32 | }
--------------------------------------------------------------------------------
/Public/Programs/Start-InternalFunction.ps1:
--------------------------------------------------------------------------------
1 | function Start-InternalFunction {
2 | <#
3 | .SYNOPSIS
4 | Starts an internal function within a specified module.
5 |
6 | .DESCRIPTION
7 | This function starts an internal function within a specified module by importing the module and executing the provided script block.
8 |
9 | .PARAMETER ScriptBlock
10 | Specifies the script block to be executed as the internal function.
11 |
12 | .PARAMETER Module
13 | Specifies the name of the module containing the internal function.
14 |
15 | .EXAMPLE
16 | Start-InternalFunction -ScriptBlock { Get-ChildItem } -Module "ExampleModule"
17 | This example starts the internal function 'Get-ChildItem' within the 'ExampleModule' module.
18 |
19 | #>
20 | [CmdletBinding()]
21 | param(
22 | [ScriptBlock] $ScriptBlock,
23 | [string] $Module
24 | )
25 |
26 | $InternalModule = Import-Module -Name $Module -PassThru
27 | & $InternalModule $ScriptBlock
28 | }
--------------------------------------------------------------------------------
/Public/Random/Get-RandomCharacters.ps1:
--------------------------------------------------------------------------------
1 | function Get-RandomCharacters {
2 | <#
3 | .SYNOPSIS
4 | Generates a random string of characters from a specified character set.
5 |
6 | .DESCRIPTION
7 | This function generates a random string of characters from a specified character set with the given length.
8 |
9 | .PARAMETER length
10 | The length of the random string to generate.
11 |
12 | .PARAMETER characters
13 | The set of characters from which to generate the random string.
14 |
15 | .EXAMPLE
16 | Get-RandomCharacters -length 8 -characters 'abcdef123'
17 | Generates a random string of 8 characters from the character set 'abcdef123'.
18 |
19 | .EXAMPLE
20 | Get-RandomCharacters -length 12 -characters 'ABC123!@#'
21 | Generates a random string of 12 characters from the character set 'ABC123!@#'.
22 | #>
23 | [cmdletbinding()]
24 | param(
25 | [int] $length,
26 | [string] $characters
27 | )
28 | if ($length -ne 0 -and $characters -ne '') {
29 | $random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
30 | $private:ofs = "" # https://blogs.msdn.microsoft.com/powershell/2006/07/15/psmdtagfaq-what-is-ofs/
31 | return [String]$characters[$random]
32 | } else {
33 | return
34 | }
35 | }
--------------------------------------------------------------------------------
/Public/Random/Get-RandomFileName.ps1:
--------------------------------------------------------------------------------
1 | function Get-RandomFileName {
2 | <#
3 | .SYNOPSIS
4 | Generates a random file name with a specified length and extension.
5 |
6 | .DESCRIPTION
7 | This function generates a random file name with a specified length and extension. The file name is created using random letters only.
8 |
9 | .PARAMETER Length
10 | The length of the random file name to generate. Default is 16.
11 |
12 | .PARAMETER Extension
13 | The extension to append to the random file name.
14 |
15 | .EXAMPLE
16 | Get-RandomFileName -Length 8 -Extension "txt"
17 | Generates a random file name with a length of 8 characters and appends the extension ".txt".
18 |
19 | .EXAMPLE
20 | Get-RandomFileName -Extension "docx"
21 | Generates a random file name with a default length of 16 characters and appends the extension ".docx".
22 | #>
23 | [cmdletbinding()]
24 | param(
25 | $Length = 16,
26 | $Extension
27 | )
28 | $File = Get-RandomStringName -Size $Length -LettersOnly -ToLower
29 | return "$File.$Extension"
30 | }
--------------------------------------------------------------------------------
/Public/Runspaces/New-Runspace.ps1:
--------------------------------------------------------------------------------
1 | function New-Runspace {
2 | <#
3 | .SYNOPSIS
4 | Creates a new runspace pool with the specified minimum and maximum runspaces.
5 |
6 | .DESCRIPTION
7 | This function creates a new runspace pool with the specified minimum and maximum runspaces. It allows for concurrent execution of PowerShell scripts.
8 |
9 | .PARAMETER minRunspaces
10 | The minimum number of runspaces to be created in the runspace pool. Default is 1.
11 |
12 | .PARAMETER maxRunspaces
13 | The maximum number of runspaces to be created in the runspace pool. Default is the number of processors plus 1.
14 |
15 | .EXAMPLE
16 | $pool = New-Runspace -minRunspaces 2 -maxRunspaces 5
17 | Creates a runspace pool with a minimum of 2 and a maximum of 5 runspaces.
18 |
19 | .EXAMPLE
20 | $pool = New-Runspace
21 | Creates a runspace pool with default minimum and maximum runspaces.
22 |
23 | #>
24 | [cmdletbinding()]
25 | param (
26 | [int] $minRunspaces = 1,
27 | [int] $maxRunspaces = [int]$env:NUMBER_OF_PROCESSORS + 1
28 | )
29 | $RunspacePool = [RunspaceFactory]::CreateRunspacePool($minRunspaces, $maxRunspaces)
30 | #ApartmentState is not available in PowerShell 6+
31 | #$RunspacePool.ApartmentState = "MTA"
32 | $RunspacePool.Open()
33 | return $RunspacePool
34 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Get-ModulesAvailability.ps1:
--------------------------------------------------------------------------------
1 | Function Get-ModulesAvailability {
2 | <#
3 | .SYNOPSIS
4 | Checks the availability of a specified module and imports it if available.
5 |
6 | .DESCRIPTION
7 | This function checks if a specified module is available. If the module is not loaded, it attempts to import it. Returns $true if the module is successfully loaded, otherwise $false.
8 |
9 | .PARAMETER Name
10 | Specifies the name of the module to check and potentially import.
11 |
12 | .EXAMPLE
13 | Get-ModulesAvailability -Name "AzureRM"
14 | Checks if the "AzureRM" module is available and imports it if not already loaded.
15 |
16 | .EXAMPLE
17 | Get-ModulesAvailability -Name "ActiveDirectory"
18 | Checks the availability of the "ActiveDirectory" module and imports it if necessary.
19 |
20 | #>
21 | [cmdletBinding()]
22 | param(
23 | [string]$Name
24 | )
25 | if (-not(Get-Module -Name $Name)) {
26 | if (Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name }) {
27 | try {
28 | Import-Module -Name $Name
29 | return $true
30 | } catch {
31 | return $false
32 | }
33 | } else {
34 | #module not available
35 | return $false
36 | }
37 | } else {
38 | return $true
39 | } #module already loaded
40 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Search-Command.ps1:
--------------------------------------------------------------------------------
1 | function Search-Command {
2 | <#
3 | .SYNOPSIS
4 | Searches for a specific command by name.
5 |
6 | .DESCRIPTION
7 | This function checks if a command with the specified name exists in the current session.
8 |
9 | .PARAMETER CommandName
10 | Specifies the name of the command to search for.
11 |
12 | .EXAMPLE
13 | Search-Command -CommandName "Get-Process"
14 | Returns $true if the command "Get-Process" exists, otherwise $false.
15 |
16 | .EXAMPLE
17 | Search-Command -CommandName "UnknownCommand"
18 | Returns $false as "UnknownCommand" does not exist as a command.
19 |
20 | #>
21 | [cmdletbinding()]
22 | param (
23 | [string] $CommandName
24 | )
25 | return [bool](Get-Command -Name $CommandName -ErrorAction SilentlyContinue)
26 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Test-AvailabilityCommands.ps1:
--------------------------------------------------------------------------------
1 | function Test-AvailabilityCommands {
2 | <#
3 | .SYNOPSIS
4 | Tests the availability of specified commands.
5 |
6 | .DESCRIPTION
7 | The Test-AvailabilityCommands function checks whether the specified commands are available in the current environment.
8 |
9 | .PARAMETER Commands
10 | Specifies an array of command names to test for availability.
11 |
12 | .EXAMPLE
13 | Test-AvailabilityCommands -Commands "Get-Process", "Get-Service"
14 | This example tests the availability of the "Get-Process" and "Get-Service" commands.
15 |
16 | .EXAMPLE
17 | Test-AvailabilityCommands -Commands "Get-Command", "Get-Help"
18 | This example tests the availability of the "Get-Command" and "Get-Help" commands.
19 |
20 | #>
21 | [cmdletBinding()]
22 | param (
23 | [string[]] $Commands
24 | )
25 | $CommandsStatus = foreach ($Command in $Commands) {
26 | $Exists = Get-Command -Name $Command -ErrorAction SilentlyContinue
27 | if ($Exists) {
28 | Write-Verbose "Test-AvailabilityCommands - Command $Command is available."
29 | } else {
30 | Write-Verbose "Test-AvailabilityCommands - Command $Command is not available."
31 | }
32 | $Exists
33 | }
34 | return $CommandsStatus
35 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Test-ForestConnectivity.ps1:
--------------------------------------------------------------------------------
1 | function Test-ForestConnectivity {
2 | <#
3 | .SYNOPSIS
4 | Tests the connectivity to the Active Directory forest.
5 |
6 | .DESCRIPTION
7 | This function tests the connectivity to the Active Directory forest by attempting to retrieve the forest information.
8 |
9 | .EXAMPLE
10 | Test-ForestConnectivity
11 | Tests the connectivity to the Active Directory forest.
12 |
13 | #>
14 | [CmdletBinding()]
15 | param(
16 |
17 | )
18 | Try {
19 | $null = Get-ADForest
20 | return $true
21 | } catch {
22 | #Write-Warning 'No connectivity to forest/domain.'
23 | return $False
24 | }
25 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Test-ModuleAvailability.ps1:
--------------------------------------------------------------------------------
1 | function Test-ModuleAvailability {
2 | <#
3 | .SYNOPSIS
4 | Tests the availability of required modules.
5 |
6 | .DESCRIPTION
7 | This function checks if the required modules are available for use.
8 |
9 | .EXAMPLE
10 | Test-ModuleAvailability
11 | Checks if the 'Get-AdForest' module is available.
12 |
13 | #>
14 | [CmdletBinding()]
15 | param(
16 |
17 | )
18 | if (Search-Command -CommandName 'Get-AdForest') {
19 | # future use
20 | } else {
21 | Write-Warning 'Modules required to run not found.'
22 | Exit
23 | }
24 | }
--------------------------------------------------------------------------------
/Public/TestFunctionality/Test-WinRM.ps1:
--------------------------------------------------------------------------------
1 | function Test-WinRM {
2 | <#
3 | .SYNOPSIS
4 | Tests the WinRM connectivity on the specified computers.
5 |
6 | .DESCRIPTION
7 | The Test-WinRM function tests the WinRM connectivity on the specified computers and returns the status of the connection.
8 |
9 | .PARAMETER ComputerName
10 | Specifies the names of the computers to test WinRM connectivity on.
11 |
12 | .EXAMPLE
13 | Test-WinRM -ComputerName "Server01", "Server02"
14 | Tests the WinRM connectivity on Server01 and Server02.
15 |
16 | .EXAMPLE
17 | Test-WinRM -ComputerName "Server03"
18 | Tests the WinRM connectivity on Server03.
19 |
20 | #>
21 | [CmdletBinding()]
22 | param (
23 | [alias('Server')][string[]] $ComputerName
24 | )
25 | $Output = foreach ($Computer in $ComputerName) {
26 | $Test = [PSCustomObject] @{
27 | Output = $null
28 | Status = $null
29 | ComputerName = $Computer
30 | }
31 | try {
32 | $Test.Output = Test-WSMan -ComputerName $Computer -ErrorAction Stop
33 | $Test.Status = $true
34 | } catch {
35 | $Test.Status = $false
36 | }
37 | $Test
38 | }
39 | $Output
40 | }
41 |
42 | #Test-WinRM -ComputerName AD1, AD2
--------------------------------------------------------------------------------
/Public/Time/Get-TimeZoneLegacy.ps1:
--------------------------------------------------------------------------------
1 | function Get-TimeZoneLegacy () {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the standard name of the current time zone.
5 |
6 | .DESCRIPTION
7 | The Get-TimeZoneLegacy function retrieves the standard name of the current time zone using the legacy method.
8 |
9 | .EXAMPLE
10 | Get-TimeZoneLegacy
11 | # Output: "Pacific Standard Time"
12 |
13 | #>
14 | return ([System.TimeZone]::CurrentTimeZone).StandardName
15 | }
16 |
--------------------------------------------------------------------------------
/Public/Time/Measure-Collection.ps1:
--------------------------------------------------------------------------------
1 | function Measure-Collection {
2 | <#
3 | .SYNOPSIS
4 | Measures the execution time of a script block and outputs the duration.
5 |
6 | .DESCRIPTION
7 | This function measures the time taken to execute a given script block and outputs the duration in days, hours, minutes, seconds, milliseconds, and ticks.
8 |
9 | .PARAMETER Name
10 | Specifies the name of the measurement.
11 |
12 | .PARAMETER ScriptBlock
13 | Specifies the script block to be executed and measured.
14 |
15 | .EXAMPLE
16 | Measure-Collection -Name "Example" -ScriptBlock { Start-Sleep -Seconds 5 }
17 | # Outputs: Name: Example, 0 days, 0 hours, 0 minutes, 5 seconds, 0 milliseconds, ticks 5000000
18 |
19 | .EXAMPLE
20 | Measure-Collection -Name "Another Example" -ScriptBlock { Get-Process }
21 | # Outputs: Name: Another Example, 0 days, 0 hours, 0 minutes, X seconds, Y milliseconds, ticks Z
22 |
23 | #>
24 | param(
25 | [string] $Name,
26 | [ScriptBlock] $ScriptBlock
27 | )
28 | $Time = [System.Diagnostics.Stopwatch]::StartNew()
29 | Invoke-Command -ScriptBlock $ScriptBlock
30 | $Time.Stop()
31 | "Name: $Name, $($Time.Elapsed.Days) days, $($Time.Elapsed.Hours) hours, $($Time.Elapsed.Minutes) minutes, $($Time.Elapsed.Seconds) seconds, $($Time.Elapsed.Milliseconds) milliseconds, ticks $($Time.Elapsed.Ticks)"
32 | }
--------------------------------------------------------------------------------
/Public/Time/Start-TimeLog.ps1:
--------------------------------------------------------------------------------
1 | function Start-TimeLog {
2 | <#
3 | .SYNOPSIS
4 | Starts a new stopwatch for logging time.
5 |
6 | .DESCRIPTION
7 | This function starts a new stopwatch that can be used for logging time durations.
8 |
9 | .EXAMPLE
10 | Start-TimeLog
11 | Starts a new stopwatch for logging time.
12 |
13 | #>
14 | [CmdletBinding()]
15 | param()
16 | [System.Diagnostics.Stopwatch]::StartNew()
17 | }
--------------------------------------------------------------------------------
/Public/Vizualization/Show-Array.ps1:
--------------------------------------------------------------------------------
1 | function Show-Array {
2 | <#
3 | .SYNOPSIS
4 | Displays the elements of an ArrayList with optional type information.
5 |
6 | .DESCRIPTION
7 | The Show-Array function displays each element of the provided ArrayList. Optionally, it can also show the type of each element.
8 |
9 | .PARAMETER List
10 | Specifies the ArrayList containing the elements to display.
11 |
12 | .PARAMETER WithType
13 | Switch parameter to include type information along with each element.
14 |
15 | .EXAMPLE
16 | $myList = New-Object System.Collections.ArrayList
17 | $myList.Add("Apple")
18 | $myList.Add(42)
19 | Show-Array -List $myList
20 | # Output:
21 | # Apple
22 | # 42
23 |
24 | .EXAMPLE
25 | $myList = New-Object System.Collections.ArrayList
26 | $myList.Add("Banana")
27 | $myList.Add(3.14)
28 | Show-Array -List $myList -WithType
29 | # Output:
30 | # Banana (Type: String)
31 | # 3.14 (Type: Double)
32 | #>
33 | [CmdletBinding()]
34 | param(
35 | [System.Collections.ArrayList] $List,
36 | [switch] $WithType
37 | )
38 | foreach ($Element in $List) {
39 | $Type = Get-ObjectType -Object $Element
40 | if ($WithType) {
41 | Write-Output "$Element (Type: $($Type.ObjectTypeName))"
42 | } else {
43 | Write-Output $Element
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/Public/Vizualization/Show-DataInVerbose.ps1:
--------------------------------------------------------------------------------
1 | function Show-DataInVerbose {
2 | <#
3 | .SYNOPSIS
4 | Displays the properties of an object in a verbose manner.
5 |
6 | .DESCRIPTION
7 | This function takes an object as input and displays each property of the object in a verbose format.
8 |
9 | .PARAMETER Object
10 | Specifies the object whose properties will be displayed.
11 |
12 | .EXAMPLE
13 | $data = [PSCustomObject]@{
14 | Name = "John Doe"
15 | Age = 30
16 | City = "New York"
17 | }
18 | Show-DataInVerbose -Object $data
19 |
20 | Description:
21 | Displays the properties of the $data object in a verbose manner.
22 |
23 | #>
24 | [CmdletBinding()]
25 | param(
26 | [Object] $Object
27 | )
28 | foreach ($O in $Object) {
29 | foreach ($E in $O.PSObject.Properties) {
30 | $FieldName = $E.Name
31 | $FieldValue = $E.Value
32 | Write-Verbose "Display-DataInVerbose - FieldName: $FieldName FieldValue: $FieldValue"
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Public/XML/Save-XML.ps1:
--------------------------------------------------------------------------------
1 | function Save-XML {
2 | <#
3 | .SYNOPSIS
4 | Saves an XML document to a specified file path.
5 |
6 | .DESCRIPTION
7 | This function saves an XML document to a specified file path using UTF-8 encoding without BOM.
8 |
9 | .PARAMETER FilePath
10 | Specifies the path where the XML document will be saved.
11 |
12 | .PARAMETER xml
13 | Specifies the XML document to be saved.
14 |
15 | .EXAMPLE
16 | Save-XML -FilePath "C:\Documents\example.xml" -xml $xmlDocument
17 | Saves the XML document $xmlDocument to the file "example.xml" located in the "C:\Documents" directory.
18 |
19 | #>
20 | param (
21 | [string] $FilePath,
22 | [System.Xml.XmlNode] $xml
23 | )
24 | $utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
25 | $writer = New-Object System.IO.StreamWriter($FilePath, $false, $utf8WithoutBom)
26 | $xml.Save( $writer )
27 | $writer.Close()
28 | }
--------------------------------------------------------------------------------
/Public/XML/Set-XML.ps1:
--------------------------------------------------------------------------------
1 | function Set-XML {
2 | <#
3 | .SYNOPSIS
4 | Sets a specific node value in an XML file.
5 |
6 | .DESCRIPTION
7 | This function sets the value of a specified node in an XML file at the given path.
8 |
9 | .PARAMETER FilePath
10 | The path to the XML file.
11 |
12 | .PARAMETER Paths
13 | An array of paths to navigate through the XML structure.
14 |
15 | .PARAMETER Node
16 | The name of the node to set the value for.
17 |
18 | .PARAMETER Value
19 | The value to set for the specified node.
20 |
21 | .EXAMPLE
22 | Set-XML -FilePath "C:\example.xml" -Paths "Root", "Child" -Node "Value" -Value "NewValue"
23 | Sets the value of the "Value" node under "Root/Child" path in the XML file to "NewValue".
24 |
25 | .NOTES
26 | File encoding is assumed to be UTF-8.
27 |
28 | #>
29 | param (
30 | [string] $FilePath,
31 | [string[]]$Paths,
32 | [string] $Node,
33 | [string] $Value
34 | )
35 | [xml]$xmlDocument = Get-Content -Path $FilePath -Encoding UTF8
36 | $XmlElement = $xmlDocument
37 | foreach ($Path in $Paths) {
38 | $XmlElement = $XmlElement.$Path
39 | }
40 | $XmlElement.$Node = $Value
41 | $xmlDocument.Save($FilePath)
42 | # Save-XML -FilePath $FilePath -xml $xmlDocument
43 | }
--------------------------------------------------------------------------------
/Tests/Format-ToTitleCase.Tests.ps1:
--------------------------------------------------------------------------------
1 | Describe -Name 'Testing Format-ToTitleCase' {
2 | It 'Test very long sentence and removee some special chars and spaces' {
3 | $String = Format-ToTitleCase -Text "This is my thing: That - No I don't want all chars" -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':'
4 | $String | Should -BeExactly 'ThisIsMyThingThatNoIDontWantAllChars'
5 | }
6 | It 'Test long sentance and remove spaces' {
7 | Format-ToTitleCase -Text 'This is my thing' -RemoveWhiteSpace | Should -BeExactly 'ThisIsMyThing'
8 | }
9 | It 'Test pipeline with 2 strings' {
10 | $String = 'me i feel', 'not feel' | Format-ToTitleCase
11 | $String[0] | Should -BeExactly 'Me I Feel'
12 | $String[1] | Should -BeExactly 'Not Feel'
13 | }
14 | It 'Testing long string' {
15 | $String = 'me i feel good' | Format-ToTitleCase
16 | $String | Should -BeExactly 'Me I Feel Good'
17 | }
18 | It 'Testing short string' {
19 | Format-ToTitleCase 'MerRe' | Should -BeExactly 'Merre'
20 | }
21 | }
--------------------------------------------------------------------------------
/Tests/Join-Uri.Tests.ps1:
--------------------------------------------------------------------------------
1 | Describe 'Join-Uri' {
2 | It 'Testing Join-Uri joining two paths - 1' {
3 | $JoinOutput = Join-Uri 'https://evotec.xyz/' '/wp-json/wp/v2/posts'
4 | $JoinOutput | Should -Be 'https://evotec.xyz/wp-json/wp/v2/posts'
5 | }
6 | It 'Testing Join-Uri joining two paths - 2' {
7 | $JoinOutput = Join-Uri 'https://evotec.xyz/' 'wp-json/wp/v2/posts'
8 | $JoinOutput | Should -Be 'https://evotec.xyz/wp-json/wp/v2/posts'
9 | }
10 | It 'Testing Join-Uri joining two paths - 3' {
11 | $JoinOutput = Join-Uri -BaseUri 'https://evotec.xyz/' -RelativeOrAbsoluteUri '/wp-json/wp/v2/posts'
12 | $JoinOutput | Should -Be 'https://evotec.xyz/wp-json/wp/v2/posts'
13 | }
14 | It 'Testing Join-Uri joining two paths - 4' {
15 | $JoinOutput = Join-Uri -BaseUri 'https://evotec.xyz/wp-json/wp/v2/' -RelativeOrAbsoluteUri '/posts'
16 | $JoinOutput | Should -Be 'https://evotec.xyz/wp-json/wp/v2/posts'
17 | }
18 | }
--------------------------------------------------------------------------------
/Tests/Join-UriQuery.ps1:
--------------------------------------------------------------------------------
1 | Describe 'Join-UriQuery' {
2 | It 'Testing Join-UriQuery joining two paths and multiple queries' {
3 | $JoinOutput = Join-UriQuery -BaseUri 'https://evotec.xyz/' -RelativeOrAbsoluteUri '/wp-json/wp/v2/posts' -QueryParameter ([ordered]@{
4 | page = 1
5 | per_page = 20
6 | search = 'SearchString'
7 | })
8 | $JoinOutput | Should -Be 'https://evotec.xyz/wp-json/wp/v2/posts?page=1&per_page=20&search=SearchString'
9 | }
10 | }
--------------------------------------------------------------------------------
/Tests/Select-Properties.Tests.ps1:
--------------------------------------------------------------------------------
1 | Describe 'Select-Properties' {
2 | It 'Select-Properties - Testing Array of PSCustomObjects' {
3 |
4 | $Object1 = [PSCustomobject] @{
5 | Name1 = '1'
6 | Name2 = '3'
7 | Name3 = '5'
8 | }
9 | $Object2 = [PSCustomobject] @{
10 | Name4 = '2'
11 | Name5 = '6'
12 | Name6 = '7'
13 | }
14 |
15 | Select-Properties -Objects $Object1, $Object2 -AllProperties | Should -Be Name1, Name2, Name3, Name4, Name5, Name6
16 | $Object1, $Object2 | Select-Properties -AllProperties | Should -Be Name1, Name2, Name3, Name4, Name5, Name6
17 | $Object1, $Object2 | Select-Properties -AllProperties -ExcludeProperty Name6 -Property Name3 | Should -Be Name3
18 |
19 | }
20 | It 'Select-Properties - Testing Array of OrderedDictionary' {
21 | $Object3 = [Ordered] @{
22 | Name1 = '1'
23 | Name2 = '3'
24 | Name3 = '5'
25 | }
26 | $Object4 = [Ordered] @{
27 | Name4 = '2'
28 | Name5 = '6'
29 | Name6 = '7'
30 | }
31 |
32 | Select-Properties -Objects $Object3, $Object4 -AllProperties | Should -Be Name1, Name2, Name3, Name4, Name5, Name6
33 | $Object3, $Object4 | Select-Properties -AllProperties | Should -Be Name1, Name2, Name3, Name4, Name5, Name6
34 | }
35 | }
--------------------------------------------------------------------------------
/Tests/Test-IsDistinguishedName.Tests.ps1:
--------------------------------------------------------------------------------
1 | Describe 'Test-IsDistinguishedName' {
2 | It 'Direct input' {
3 | Test-IsDistinguishedName -Identity 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Should -Be $true
4 | Test-IsDistinguishedName -Identity 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Should -Be $true
5 | Test-IsDistinguishedName -Identity 'ad.evotec.pl' | Should -Be $false
6 | Test-IsDistinguishedName -Identity 'test.evotec.pl' | Should -Be $false
7 | Test-IsDistinguishedName -Identity 'NT AUTHORITY\INTERACTIVE' | Should -Be $false
8 | Test-IsDistinguishedName -Identity 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Should -Be $true
9 |
10 | }
11 | It 'Pipeline input' {
12 | 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Test-IsDistinguishedName | Should -Be $true
13 | 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Test-IsDistinguishedName | Should -Be $true
14 | 'ad.evotec.pl' | Test-IsDistinguishedName | Should -Be $false
15 | 'test.evotec.pl' | Test-IsDistinguishedName | Should -Be $false
16 | 'NT AUTHORITY\INTERACTIVE' | Test-IsDistinguishedName | Should -Be $false
17 | 'CN=Domain Admins,CN=Users,DC=ad,DC=evotec,DC=pl' | Test-IsDistinguishedName | Should -Be $true
18 | }
19 | }
--------------------------------------------------------------------------------