From e9dbfa45da4ca22ca0c8ffe3d68911db63626337 Mon Sep 17 00:00:00 2001 From: Michael Hex Date: Sun, 27 Nov 2016 20:14:01 +0100 Subject: [PATCH] Added Set-RegistryValue() and Get-RegistryValue() --- MPSXM-Debug_Tests.ps1 | 33 +++++ MPSXM.psm1 | 321 ++++++++++++++++++++++++++++++++++-------- README.md | 266 +++++++++++++++++----------------- 3 files changed, 432 insertions(+), 188 deletions(-) diff --git a/MPSXM-Debug_Tests.ps1 b/MPSXM-Debug_Tests.ps1 index 10b8188..b255a3c 100644 --- a/MPSXM-Debug_Tests.ps1 +++ b/MPSXM-Debug_Tests.ps1 @@ -15,6 +15,39 @@ Import-Module "$PSScriptRoot\MPSXM.psm1" -Force Clear-Host +$reg="HKCU\Software\MPSXM" + +#Set-RegistryValue -Path $regPath -Value "Value of default key" +#Set-RegistryValue -Path $regPath -Name "RegTest 1" -Value 0 + + +#Set-RegistryValue -Path $regPath -Name $null -Value 0 + +#Write to (Default) value +Set-RegistryValue -Path $reg -Value "Value for (default)" + +#Write as REG_DWORD because the value is an int +Set-RegistryValue -Path $regPath -Name "My DWORD Value" -Value 1 + +#Write as REG_QWORD because the value is a long +Set-RegistryValue -Path $regPath -Name "My QWORD Value" -Value ([long]123) + +#Write an int as REQ_QWORD by using the prameter QWordb +Set-RegistryValue -Path $regPath -Name "My QWORD Value 2" -Value 2 -Type QWord + + +$testRead=Get-RegistryValue -Path $regPath -Name "My DWORD Value" +write-host "Read My DWORD Value: [$testRead]" + +$testRead=Get-RegistryValue -Path $regPath -Name "My DWORD Value DOES NOT EXIST" -DefaultValue 999 +write-host "Read My DWORD Value: [$testRead]" + +$testRead=Get-RegistryValue -Path $regPath -DefaultValue "Not set" +write-host "Read (Default) value: [$testRead]" + +$testRead=Get-RegistryValue -Path "$regPath\XyZ" -DefaultValue "Default Value" +write-host "Read (Default) value non existing path: [$testRead]" + write-host "*** ENDE ***" diff --git a/MPSXM.psm1 b/MPSXM.psm1 index 5926bc0..ed0347d 100644 --- a/MPSXM.psm1 +++ b/MPSXM.psm1 @@ -1,5 +1,5 @@ # Michael's PowerShell eXtension Module -# Version 3.19.0 +# Version 3.20.0 # https://github.com/texhex/MPSXM # # Copyright © 2010-2016 Michael 'Tex' Hex @@ -54,6 +54,7 @@ $ErrorActionPreference = 'Stop' # Get-StringIsNullOrWhiteSpace() should be deleted (replaced with Test-String) # Get-StringHasData() should be deleted (replaced with Test-String) # Get-RunningInISE() should be deleted (replaced with Test-InISE) +# Add-RegistryValue() should be be deleted (replaced with Set-RegistryValue) function Get-CurrentProcessBitness() { @@ -75,14 +76,14 @@ function Get-CurrentProcessBitness() #> [OutputType([bool])] param ( - [Parameter(ParameterSetName="64bit",Mandatory=$True)] - [switch]$Is64bit, - [Parameter(ParameterSetName="32bit",Mandatory=$True)] [switch]$Is32bit, [Parameter(ParameterSetName="WoW",Mandatory=$True)] - [switch]$IsWoW + [switch]$IsWoW, + + [Parameter(ParameterSetName="64bit",Mandatory=$True)] + [switch]$Is64bit ) switch ($PsCmdlet.ParameterSetName) @@ -148,11 +149,11 @@ function Get-OperatingSystemBitness() #> [OutputType([bool])] param ( - [Parameter(ParameterSetName="64bit",Mandatory=$True)] - [switch]$Is64bit, - [Parameter(ParameterSetName="32bit",Mandatory=$True)] - [switch]$Is32bit + [switch]$Is32bit, + + [Parameter(ParameterSetName="64bit",Mandatory=$True)] + [switch]$Is64bit ) switch ($PsCmdlet.ParameterSetName) @@ -706,52 +707,6 @@ param( } -function Add-RegistryValue { -<# - .SYNOPSIS - Adds a value to the given registry path. Right now only string values are supported. - - .PARAMETER Path - The registry path, e.g. HKCU:\Software\TEMP\TSVARS - - .PARAMETER Name - The name of the registry value - - .PARAMETER Value - The value - - .PARAMETER REG_SZ - The data will be written as REG_SZ - - .OUTPUTS - None -#> -param( - [Parameter(Mandatory=$True,Position=1)] - [ValidateNotNullOrEmpty()] - [string]$Path, - - [Parameter(Mandatory=$True,Position=2)] - [ValidateNotNullOrEmpty()] - [string]$Name, - - [Parameter(Mandatory=$True,Position=3)] - [ValidateNotNull()] - [string]$Value, - - [Parameter(Mandatory=$True)] - [switch]$REG_SZ -) - - if( !(Test-Path $Path) ) - { - $ignored=New-Item -Path $Path -Force - } - - $ignored=New-ItemProperty -Path $path -Name $name -Value $value -PropertyType String -Force -} - - #From http://stackingcode.com/blog/2011/10/27/quick-random-string # by Adam Boddington function Get-RandomString { @@ -1201,6 +1156,52 @@ param ( $qrList += $QuickRef } #foreach + + + #By default, get-help will return the functions names from a module sorted by Verb, but not the noun. + #Given that some functions deal with the same nouns, it makes more sense to sort them by noun, then by verb. + $objectCount=($qrList | Measure-Object).Count + + if ( $objectCount -gt 1 ) + { + $dict=New-Dictionary -KeyType string -ValueType int + + for ($i = 0; $i -lt $qrList.Count; $i++) + { + #We first need to reverse verb-noun to noun-verb + $curFunction=$qrList[$i].Name + $posHyphen=$curFunction.IndexOf("-") + $sortName="" + + if ( -not $posHyphen -ge 2) + { + #function doesn't use a hypen, use as is + $sortName=$curFunction + } + else + { + #Turn a function like "Get-Something" into "Something-Get" + $sortName=$curFunction.SubString($posHyphen+1) + $sortName+="-" + $sortName+=$curFunction.SubString(0,$posHyphen) + } + + $dict.Add($sortName, $i) + } + + #Now sort the list based on the name + $sortedList=$dict.GetEnumerator() | Sort-Object -Property "Key" + + #Create a new array with the original values in the new order + $qrListTemp=@() + foreach ($entry in $sortedList) + { + $qrListTemp +=$qrList[$entry.Value] + } + + #Replace the current qrList with the objects from this list + $qrList=$qrListTemp + } #$qrList contains one or more objects we can use - check which output the caller wants @@ -1831,3 +1832,213 @@ param ( } #function + + +function Add-RegistryValue { +<# + .SYNOPSIS + Adds a value to the given registry path. Uses [Set-RegistryValue] internally. + + .PARAMETER Path + The registry path, e.g. HKCU:\Software\TEMP\TSVARS + + .PARAMETER Name + The name of the registry value + + .PARAMETER Value + The value + + .PARAMETER REG_SZ + The data will be written as REG_SZ + + .OUTPUTS + None +#> +param( + [Parameter(Mandatory=$True,Position=1)] + [ValidateNotNullOrEmpty()] + [string]$Path, + + [Parameter(Mandatory=$True,Position=2)] + [ValidateNotNullOrEmpty()] + [string]$Name, + + [Parameter(Mandatory=$True,Position=3)] + [ValidateNotNull()] + [string]$Value, + + [Parameter(Mandatory=$True)] + [switch]$REG_SZ +) + + if( !(Test-Path $Path) ) + { + $ignored=New-Item -Path $Path -Force + } + + $ignored=New-ItemProperty -Path $path -Name $name -Value $value -PropertyType String -Force +} + + +function Set-RegistryValue +{ +<# + .SYNOPSIS + Writes a registry value in the given registry path. + + .PARAMETER Path + The registry path, e.g. HKCU\Software\MPSXM\ + + .PARAMETER Name + The name of the registry value. If not defined, the (default) value is used + + .PARAMETER Value + The value to be written + + .PARAMETER Type + The data type used in the registry (REG_xx). If not specified, the type of the given value will be used to assign DWord, QWord or String. + + .OUTPUTS + None +#> +param( + [Parameter(Mandatory=$true,Position=1)] + [ValidateNotNullOrEmpty()] + [string]$Path, + + [Parameter(Mandatory=$false)] + [string]$Name, + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + $Value, + + [Parameter(Mandatory=$false)] + [Microsoft.Win32.RegistryValueKind]$Type=[Microsoft.Win32.RegistryValueKind]::Unknown +) + + #Normal registry path just use ROOT\Path e.g. HKCU\Software\MPSXM. PowerShell (because it uses a provider) uses ROOT:\Path + #Check if the fifth character is a ":" and if not, add it so PowerShell knows we want to write to the registry + if ( ($Path.Substring(4,1) -eq ":") ) + { + $regPath=$Path + } + else + { + $regPath=$Path.Insert(4,":") + } + + #Create the path if it does not exist + if( -not (Test-Path $regPath -PathType Container) ) + { + $ignored=New-Item -Path $regPath -Force + } + + #check if value name was given. If not, write to (default) + if ( Test-String -IsNullOrWhiteSpace $Name ) + { + #default values only support string, so we always convert to string + $ignored=Set-Item -Path $regPath -Value $value.ToString() + } + else + { + if ( $Type -eq [Microsoft.Win32.RegistryValueKind]::Unknown ) + { + #type was not given, figure it out ourselves + #"String, ExpandString, Binary, DWord, MultiString, QWord, Unknown". + if ( $Value -is [int]) + { + $Type=[Microsoft.Win32.RegistryValueKind]::DWord + } + elseif ( $Value -is [long]) + { + $Type=[Microsoft.Win32.RegistryValueKind]::QWord + } + else + { + $Type=[Microsoft.Win32.RegistryValueKind]::String + } + } + + $ignored=New-ItemProperty -Path $regPath -Name $name -Value $value -PropertyType $Type -Force + } +} + + + +function Get-RegistryValue +{ +<# + .SYNOPSIS + Reads a registry value. + + .PARAMETER Path + The registry path, e.g. HKCU\Software\MPSXM\ + + .PARAMETER Name + The name of the registry value to be read. If not defined, the (default) value is used + + .PARAMETER DefaultValue + The value to return if name does not exist. If not defined, $null is returned if Name does not exist + + .OUTPUTS + Varies +#> +param( + [Parameter(Mandatory=$true,Position=1)] + [ValidateNotNullOrEmpty()] + [string]$Path, + + [Parameter(Mandatory=$false)] + [string]$Name, + + [Parameter(Mandatory=$false)] + $DefaultValue=$null +) + + #Normal registry path just use ROOT\Path e.g. HKCU\Software\MPSXM. PowerShell (because it uses a provider) uses ROOT:\Path + #Check if the fifth character is a ":" and if not, add it so PowerShell knows we want to write to the registry + if ( ($Path.Substring(4,1) -eq ":") ) + { + $regPath=$Path + } + else + { + $regPath=$Path.Insert(4,":") + } + + if( -not (Test-Path $regPath -PathType Container) ) + { + #Path does not exist, return default value + return $DefaultValue + } + else + { + #This commands read ALL values from the path. No idea if this is bad or can be ignored. + $regVals=Get-ItemProperty -Path $regPath + if( -not $regVals ) + { + return $DefaultValue + } + else + { + #Was a name given? If not, use (default) + if ( Test-String -IsNullOrWhiteSpace $Name) + { + $Name="(default)" + } + + $regValue=Get-Member -InputObject $regVals -Name $Name + if( -not $regValue ) + { + return $DefaultValue + } + else + { + #return the real value + return $regVals.$Name + } + } + } + +} diff --git a/README.md b/README.md index d89aec0..fee875e 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,36 @@ Examples for each function are included in ``MPSXM-QuickTests.ps1``. -### Add-RegistryValue ### -Adds a value to the given registry path. Right now only string values are supported. +### Test-Admin ### +Determines if the current powershell is elevated (running with administrator privileges). ```powershell -Add-RegistryValue [-Path] [-Name] [-Value] -REG_SZ +Test-Admin ``` - - *Path* - The registry path, e.g. HKCU:\Software\TEMP\TSVARS - - *Name* - The name of the registry value - - *Value* - The value - - *REG_SZ* - The data will be written as REG_SZ + +### Get-ComputerLastBootupTime ### +Returns the date and time of the last bootup time of this computer. +```powershell +Get-ComputerLastBootupTime +``` + +### Exit-Context ### +Will exit from the current context and sets an exit code. Nothing will be done when running in ISE. +```powershell +Exit-Context [-ExitCode] [-Force] +``` + - *ExitCode* - The number the exit code should be set to. + - *Force* - Will enfore full exit by using ENVIRONMENT.Exit() + +### Get-CurrentProcessBitness ### +Returns information about the current powershell process. +```powershell +Get-CurrentProcessBitness -Is64bit +Get-CurrentProcessBitness -Is32bit +Get-CurrentProcessBitness -IsWoW +``` + - *Is64bit* - Returns $True if the current script is running as 64-bit process. + - *Is32bit* - Returns $True if the current script is running as 32-bit process. + - *IsWoW* - Returns $True if the current script is running as 32-bit process on a 64-bit machine (Windows on Windows). ### ConvertFrom-DateTimeString ### Converts a string (created by ConvertTo-DateTimeString() to a DateTime. If the given string contains a time zone (...+/-01:00), @@ -36,13 +57,6 @@ ConvertFrom-DateTimeString [-DateTimeString] ``` - *DateTimeString* - The string to be converted to a DateTime -### ConvertFrom-UTC ### -Converts a given Coordinated Universal Time (UTC) DateTime to local time. -```powershell -ConvertFrom-UTC [-DateTime] -``` - - *DateTime* - The DateTime to be converted to local time from UTC. Inputs not in UTC will result in an exception. - ### ConvertTo-DateTimeString ### Converts a DateTime to a string as definied by ISO 8601. The result will be [2016-11-24 14:59:16.718+01:00] for local and [2016-11-19 14:24:09.718Z] for UTC values. ```powershell @@ -55,53 +69,57 @@ ConvertTo-DateTimeString [-DateTime] [-HideMilliseconds] -ForceUTC - *UTC* - Convert the DateTime to UTC before converting it to a string. - *ForceUTC* - Ignore the time zone/kind (Local, Unspecified, UTC) of the given DateTime and use it as if it were UTC already. -### ConvertTo-HumanizedBytesString ### -Returns a string optimized for readability. -```powershell -ConvertTo-HumanizedBytesString [-bytes] -``` - - *bytes* - The value of bytes that should be returned as humanized string. - -### ConvertTo-UTC ### -Converts a given DateTime to a Coordinated Universal Time (UTC) DateTime. +### New-Dictionary ### +Returns a dictionary that can be used like a hashtable (Key-Value pairs) but the pairs are not sorted by the key as in a hashtable ```powershell -ConvertTo-UTC [-DateTime] [-ForceUTC] +New-Dictionary -StringPairs +New-Dictionary -StringKey +New-Dictionary -KeyType -ValueType ``` - - *DateTime* - The DateTime to be converted to UTC. A DateTime without time zone (Kind=Unspecified) is assumed to be in local time. Values already in UTC will be returned as is. - - *ForceUTC* - Ignore the time zone/kind (Local, Unspecified, UTC) of the given DateTime and return the same date and time as the input as UTC + - *StringPairs* - Both the key and the value of the dictionary are strings. Accessing values using object[Key] is case-insensitve. + - *StringKey* - The key of the dictionary is of type string, the value is of type PSObject. Accessing values using object[Key] is case-insensitve. + - *KeyType* - Defines the type used for the key. Accessing values using object[Key] is NOT case-insensitve, it's case-sensitive. + - *ValueType* - Defines the type used for the value. -### ConvertTo-Version ### -Returns a VERSION object with the version number converted from the given text. +### New-Exception ### +Generates an exception ready to be thrown, the expected usage is [throw New-Exception -(TypeOfException) "Explanation why exception is thrown"] ```powershell -ConvertTo-Version [[-Text] ] [-RespectLeadingZeros] +New-Exception -InvalidArgument [[-Explanation] ] [-NoCallerName] +New-Exception -InvalidOperation [[-Explanation] ] [-NoCallerName] +New-Exception -InvalidFormat [[-Explanation] ] [-NoCallerName] +New-Exception -FileNotFound [[-Explanation] ] [-NoCallerName] +New-Exception -DirectoryNotFound [[-Explanation] ] [-NoCallerName] ``` - - *Text* - The input string to be converted, e.g. 1.3.44. - - *RespectLeadingZeros* - Respect leading zeros by shifting the parts right, e.g. 1.02.3 becomes 1.0.2.3. + - *InvalidArgument* - The exception it thrown because of a value does not fall within the expected range + - *InvalidOperation* - The exception is thrown because the operation is not valid due to the current state of the object + - *InvalidFormat* - The exception is thrown because one of the identified items was in an invalid format + - *FileNotFound* - The exception is thrown because a file can not be found/accessed + - *DirectoryNotFound* - The exception is thrown because a directory can not be found/accessed + - *Explanation* - A description why the exception is thrown. If empty, a standard text matching the type of exception beeing generated is used + - *NoCallerName* - By default, the name of the function or script generating the exception is included in the explanation -### Exit-Context ### -Will exit from the current context and sets an exit code. Nothing will be done when running in ISE. +### ConvertTo-HumanizedBytesString ### +Returns a string optimized for readability. ```powershell -Exit-Context [-ExitCode] [-Force] +ConvertTo-HumanizedBytesString [-bytes] ``` - - *ExitCode* - The number the exit code should be set to. - - *Force* - Will enfore full exit by using ENVIRONMENT.Exit() + - *bytes* - The value of bytes that should be returned as humanized string. -### Get-ComputerLastBootupTime ### -Returns the date and time of the last bootup time of this computer. +### Test-IsISE ### +Returns if the current script is executed by Windows PowerShell ISE ```powershell -Get-ComputerLastBootupTime +Test-IsISE ``` -### Get-CurrentProcessBitness ### -Returns information about the current powershell process. +### Show-MessageBox ### +Shows the message box to the user using a message box. ```powershell -Get-CurrentProcessBitness -Is64bit -Get-CurrentProcessBitness -Is32bit -Get-CurrentProcessBitness -IsWoW +Show-MessageBox [-Message] [[-Titel] ] [-Critical] [-Huge] ``` - - *Is64bit* - Returns $True if the current script is running as 64-bit process. - - *Is32bit* - Returns $True if the current script is running as 32-bit process. - - *IsWoW* - Returns $True if the current script is running as 32-bit process on a 64-bit machine (Windows on Windows). + - *Message* - The message to be displayed inside the message box. + - *Titel* - The title for the message box. If empty, the full script filename is used. + - *Critical* - Show an critical icon inside the message box. If not set, an information icon is used. + - *Huge* - Adds extra lines to the message to ensure the message box appears bigger. ### Get-ModuleAvailable ### Returns true if the module exist; it uses a a method that is about 10 times faster then using Get-Module -ListAvailable @@ -135,6 +153,16 @@ Get-RandomString [-Length] ``` - *Length* - The length of the string that should be generated. +### Add-RegistryValue ### +Adds a value to the given registry path. Right now only string values are supported. +```powershell +Add-RegistryValue [-Path] [-Name] [-Value] -REG_SZ +``` + - *Path* - The registry path, e.g. HKCU:\Software\TEMP\TSVARS + - *Name* - The name of the registry value + - *Value* - The value + - *REG_SZ* - The data will be written as REG_SZ + ### Get-RunningInISE ### Returns if the current script is executed by Windows PowerShell ISE (uses Test-IsISE internally) ```powershell @@ -148,6 +176,13 @@ Get-StringHasData [-string] ``` - *string* - The string value to be checked +### Read-StringHashtable ### +Reads a hashtable from a file where the Key-Value pairs are stored as Key==Value +```powershell +Read-StringHashtable [-File] +``` + - *File* - The file to read the hashtable from + ### Get-StringIsNullOrWhiteSpace ### Returns true if the string is either $null, empty, or consists only of white-space characters (uses [Test-String -IsNullOrWhiteSpace] internally) ```powershell @@ -155,75 +190,27 @@ Get-StringIsNullOrWhiteSpace [-string] ``` - *string* - The string value to be checked -### Get-TempFolder ### -Returns a path to the temporary folder without any (8+3) paths in it -```powershell -Get-TempFolder -``` - -### Get-TrimmedString ### -Removes white-space characters from the given string. By default, it removes all leading and trailing white-spaces chracters. -```powershell -Get-TrimmedString [[-String] ] -Get-TrimmedString [[-String] ] -StartOnly -Get-TrimmedString [[-String] ] -EndOnly -Get-TrimmedString [[-String] ] -Equalize -Get-TrimmedString [[-String] ] -RemoveDuplicates -Get-TrimmedString [[-String] ] -RemoveAll -``` - - *String* - The string to be trimmed - - *StartOnly* - Only remove leading white-space chracters - - *EndOnly* - Only remove trailing white-space chracters - - *Equalize* - Removes all leading and trailing white-space characters, then replace any character considered to be a white-space with the standard white-space character (U+0020) - - *RemoveDuplicates* - Removes all leading and trailing white-space characters, then replace any white-space duplicates with -one white-space (U+0020) - - *RemoveAll* - Removes all white-space chracters from the string - -### New-Dictionary ### -Returns a dictionary that can be used like a hashtable (Key-Value pairs) but the pairs are not sorted by the key as in a hashtable -```powershell -New-Dictionary -StringPairs -New-Dictionary -StringKey -New-Dictionary -KeyType -ValueType -``` - - *StringPairs* - Both the key and the value of the dictionary are strings. Accessing values using object[Key] is case-insensitve. - - *StringKey* - The key of the dictionary is of type string, the value is of type PSObject. Accessing values using object[Key] is case-insensitve. - - *KeyType* - Defines the type used for the key. Accessing values using object[Key] is NOT case-insensitve, it's case-sensitive. - - *ValueType* - Defines the type used for the value. - -### New-Exception ### -Generates an exception ready to be thrown, the expected usage is [throw New-Exception -(TypeOfException) "Explanation why exception is thrown"] -```powershell -New-Exception -InvalidArgument [[-Explanation] ] [-NoCallerName] -New-Exception -InvalidOperation [[-Explanation] ] [-NoCallerName] -New-Exception -InvalidFormat [[-Explanation] ] [-NoCallerName] -New-Exception -FileNotFound [[-Explanation] ] [-NoCallerName] -New-Exception -DirectoryNotFound [[-Explanation] ] [-NoCallerName] -``` - - *InvalidArgument* - The exception it thrown because of a value does not fall within the expected range - - *InvalidOperation* - The exception is thrown because the operation is not valid due to the current state of the object - - *InvalidFormat* - The exception is thrown because one of the identified items was in an invalid format - - *FileNotFound* - The exception is thrown because a file can not be found/accessed - - *DirectoryNotFound* - The exception is thrown because a directory can not be found/accessed - - *Explanation* - A description why the exception is thrown. If empty, a standard text matching the type of exception beeing generated is used - - *NoCallerName* - By default, the name of the function or script generating the exception is included in the explanation - -### Read-StringHashtable ### -Reads a hashtable from a file where the Key-Value pairs are stored as Key==Value +### Test-String ### +Tests the given string for a condition ```powershell -Read-StringHashtable [-File] +Test-String [[-String] ] -HasData +Test-String [[-String] ] -IsNullOrWhiteSpace +Test-String [[-String] ] -Contains [[-SearchFor] ] [-CaseSensitive] +Test-String [[-String] ] -StartsWith [[-SearchFor] ] [-CaseSensitive] ``` - - *File* - The file to read the hashtable from + - *String* - The string the specified operation should be performed on + - *HasData* - Returns true if the string contains data (not $null, empty or only white spaces) + - *IsNullOrWhiteSpace* - Returns true if the string is either $null, empty, or consists only of white-space characters. + - *Contains* - Returns true if string contains the text in SearchFor. A case-insensitive (ABCD = abcd) is performed by default. + - *StartsWith* - Returns true if the string starts with the text in SearchFor. A case-insensitive (ABCD = abcd) is performed by default. + - *SearchFor* - The string beeing sought + - *CaseSensitive* - Perform an operation that respect letter casing, so [ABC] is different from [aBC]. -### Show-MessageBox ### -Shows the message box to the user using a message box. +### Get-TempFolder ### +Returns a path to the temporary folder without any (8+3) paths in it ```powershell -Show-MessageBox [-Message] [[-Titel] ] [-Critical] [-Huge] +Get-TempFolder ``` - - *Message* - The message to be displayed inside the message box. - - *Titel* - The title for the message box. If empty, the full script filename is used. - - *Critical* - Show an critical icon inside the message box. If not set, an information icon is used. - - *Huge* - Adds extra lines to the message to ensure the message box appears bigger. ### Start-TranscriptIfSupported ### Starts a transscript, but ignores if the host does not support it. @@ -234,6 +221,12 @@ Start-TranscriptIfSupported [[-Path] ] [[-Name] ] [-NewLog] - *Name* - The name of the log file. If empty, the file name of the calling script is used. - *NewLog* - Create a new log file every time a transcript is started ([Name].log-XX.txt) +### Stop-TranscriptIfSupported ### +Stops a transscript, but ignores if the host does not support it. +```powershell +Stop-TranscriptIfSupported +``` + ### Start-TranscriptTaskSequence ### If the scripts runs in MDT or SCCM, the transcript will be stored in the path LOGPATH defines. If not, C:\WINDOWS\TEMP is used. ```powershell @@ -241,39 +234,46 @@ Start-TranscriptTaskSequence [-NewLog] ``` - *NewLog* - When set, will create a log file every time a transcript is started -### Stop-TranscriptIfSupported ### -Stops a transscript, but ignores if the host does not support it. +### Get-TrimmedString ### +Removes white-space characters from the given string. By default, it removes all leading and trailing white-spaces chracters. ```powershell -Stop-TranscriptIfSupported +Get-TrimmedString [[-String] ] +Get-TrimmedString [[-String] ] -StartOnly +Get-TrimmedString [[-String] ] -EndOnly +Get-TrimmedString [[-String] ] -Equalize +Get-TrimmedString [[-String] ] -RemoveDuplicates +Get-TrimmedString [[-String] ] -RemoveAll ``` + - *String* - The string to be trimmed + - *StartOnly* - Only remove leading white-space chracters + - *EndOnly* - Only remove trailing white-space chracters + - *Equalize* - Removes all leading and trailing white-space characters, then replace any character considered to be a white-space with the standard white-space character (U+0020) + - *RemoveDuplicates* - Removes all leading and trailing white-space characters, then replace any white-space duplicates with +one white-space (U+0020) + - *RemoveAll* - Removes all white-space chracters from the string -### Test-Admin ### -Determines if the current powershell is elevated (running with administrator privileges). +### ConvertFrom-UTC ### +Converts a given Coordinated Universal Time (UTC) DateTime to local time. ```powershell -Test-Admin +ConvertFrom-UTC [-DateTime] ``` + - *DateTime* - The DateTime to be converted to local time from UTC. Inputs not in UTC will result in an exception. -### Test-IsISE ### -Returns if the current script is executed by Windows PowerShell ISE +### ConvertTo-UTC ### +Converts a given DateTime to a Coordinated Universal Time (UTC) DateTime. ```powershell -Test-IsISE +ConvertTo-UTC [-DateTime] [-ForceUTC] ``` + - *DateTime* - The DateTime to be converted to UTC. A DateTime without time zone (Kind=Unspecified) is assumed to be in local time. Values already in UTC will be returned as is. + - *ForceUTC* - Ignore the time zone/kind (Local, Unspecified, UTC) of the given DateTime and return the same date and time as the input as UTC -### Test-String ### -Tests the given string for a condition +### ConvertTo-Version ### +Returns a VERSION object with the version number converted from the given text. ```powershell -Test-String [[-String] ] -HasData -Test-String [[-String] ] -IsNullOrWhiteSpace -Test-String [[-String] ] -Contains [[-SearchFor] ] [-CaseSensitive] -Test-String [[-String] ] -StartsWith [[-SearchFor] ] [-CaseSensitive] +ConvertTo-Version [[-Text] ] [-RespectLeadingZeros] ``` - - *String* - The string the specified operation should be performed on - - *HasData* - Returns true if the string contains data (not $null, empty or only white spaces) - - *IsNullOrWhiteSpace* - Returns true if the string is either $null, empty, or consists only of white-space characters. - - *Contains* - Returns true if string contains the text in SearchFor. A case-insensitive (ABCD = abcd) is performed by default. - - *StartsWith* - Returns true if the string starts with the text in SearchFor. A case-insensitive (ABCD = abcd) is performed by default. - - *SearchFor* - The string beeing sought - - *CaseSensitive* - Perform an operation that respect letter casing, so [ABC] is different from [aBC]. + - *Text* - The input string to be converted, e.g. 1.3.44. + - *RespectLeadingZeros* - Respect leading zeros by shifting the parts right, e.g. 1.02.3 becomes 1.0.2.3.