This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-TextWithin { | |
<# | |
.SYNOPSIS | |
Get the text between two surrounding characters (e.g. brackets, quotes, or custom characters) | |
.DESCRIPTION | |
Use RegEx to retrieve the text within enclosing characters. | |
.PARAMETER Text | |
The text to retrieve the matches from. | |
.PARAMETER WithinChar | |
Single character, indicating the surrounding characters to retrieve the enclosing text for. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$testText = 'Peter <[email protected]>, Paul <[email protected]>, Zoe <[email protected]>' | |
$pattern = '(?<=\<).+?(?=\>)' | |
[regex]::Matches($testText, $pattern).Value | |
<# | |
output | |
[email protected] | |
[email protected] | |
[email protected] | |
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#assuming the script is in the same folder as the FlaUI assemblies | |
Add-Type -Path "$PSScriptRoot\FlaUI.Core.1.3.0\lib\net45\FlaUI.Core.dll" | |
Add-Type -Path "$PSScriptRoot\FlaUI.UIA3.1.3.1\lib\net45\FlaUI.UIA3.dll" | |
$calc = [Diagnostics.Process]::Start('calc') | |
#wait for the UI to appear | |
$null = $calc.WaitForInputIdle(5000) | |
sleep -s 2 | |
$calcWindowId = ((Get-Process).where{ $_.MainWindowTitle -eq 'Calculator' })[0].Id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$null = mkdir test | |
cd test | |
Install-Package -Name FlaUI.Core -ProviderName NuGet -RequiredVersion 1.3.1 -SkipDependencies -Destination $pwd -Source nuget.org | |
Install-Package -Name FlaUI.CORE -ProviderName NuGet -RequiredVersion 1.3.0 -SkipDependencies -Destination $pwd -Source nuget.org | |
Find-Package flauinspect | Install-Package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName UIAutomationClient | |
Add-Type -AssemblyName UIAutomationTypes | |
$calc = [Diagnostics.Process]::Start('calc') | |
#wait for the UI to appear | |
$null = $calc.WaitForInputIdle(5000) | |
sleep -s 2 | |
$calcWindowId = ((Get-Process).where{$_.MainWindowTitle -eq 'Calculator'})[0].Id | |
$root = [Windows.Automation.AutomationElement]::RootElement | |
$condition = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ProcessIdProperty, $calcWindowId) | |
$calcUI = $root.FindFirst([Windows.Automation.TreeScope]::Children, $condition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { | |
# property to take additional format strings for transformations | |
[string[]]$AdditionalFormatStrings | |
# default constructor: | |
DateTransformAttribute() : base() { } | |
# 2nd constructor with parameter AdditionalFormatStrings | |
DateTransformAttribute([string[]]$AdditionalFormatStrings) : base() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define a format that is supported by our attribute | |
$stringDate = '4/14 4:12PM' | |
# try it first with the normal datetime type | |
[datetime]'4/14 4:12PM' | |
# this threw an error | |
# define a variable that utilizes the attribute | |
[datetime][DateTransform()]$dt = $stringDate | |
# no error | |
$dt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute { | |
# property to take additional format strings for transformations | |
[string[]]$AdditionalFormatStrings | |
# default constructor: | |
DateTransformAttribute() : base() { } | |
# 2nd constructor with parameter AdditionalFormatStrings | |
DateTransformAttribute([string[]]$AdditionalFormatStrings) : base() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[datetime]::ParseExact('08|12|2009 4:33 PM','dd|MM|yyyy h:m tt',$Null) | |
#returns Tuesday, December 8, 2009 4:33:00 PM on an English system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[Parameter(Mandatory)] | |
[ArgumentCompleter( | |
{ | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
$allTimezones = Get-TimeZone -ListAvailable | Group-Object DisplayName -AsHashTable -AsString | |
$allTimezones.GetEnumerator() | Where-Object { $_.Name -like "*${wordToComplete}*" } | | |
Sort-Object { $_.Value.Displayname }-Unique | ForEach-Object { | |
New-Object System.Management.Automation.CompletionResult ( | |
"'$($_.Value.Id)'", |
NewerOlder