Add src/helpers.ps1
This commit is contained in:
28
src/helpers.ps1
Normal file
28
src/helpers.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
function Test-ComputerName {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Name
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Name)) { return $false }
|
||||
if ($Name.Length -gt 15) { return $false }
|
||||
if ($Name -notmatch '^[A-Za-z0-9-]+$') { return $false }
|
||||
return $true
|
||||
}
|
||||
|
||||
function Get-TaskHandlerName {
|
||||
param([object]$Task)
|
||||
|
||||
foreach ($p in @('HandlerFn','Handler','Fn')) {
|
||||
if ($Task.PSObject.Properties.Name -contains $p) {
|
||||
$v = ([string]$Task.$p).Trim().TrimStart('/')
|
||||
if (-not [string]::IsNullOrWhiteSpace($v)) { return $v }
|
||||
}
|
||||
}
|
||||
|
||||
$n = ([string]$Task.Name).Trim().TrimStart('/')
|
||||
if (-not [string]::IsNullOrWhiteSpace($n)) { return "Invoke-$n" }
|
||||
|
||||
return $null
|
||||
}
|
||||
Reference in New Issue
Block a user