From 9453383f34c8cde3a032b006523b63b5f17646be Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sat, 5 Oct 2024 18:39:00 +0200 Subject: [PATCH] add helper function Get-NetboxSlug.ps1 --- Functions/Helpers/Get-NetboxSlug.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Functions/Helpers/Get-NetboxSlug.ps1 diff --git a/Functions/Helpers/Get-NetboxSlug.ps1 b/Functions/Helpers/Get-NetboxSlug.ps1 new file mode 100644 index 0000000..b026b81 --- /dev/null +++ b/Functions/Helpers/Get-NetboxSlug.ps1 @@ -0,0 +1,16 @@ +function Get-NetboxSlug { + param ( + [Parameter(ValueFromPipeline)] + [string]$slug, + + [uint16]$chars = 100 + ) + + process { + return $slug -replace '[^\-.\w\s]', '' ` + -replace '[^a-zA-Z0-9-_ ]', '' ` + -replace '^[\s.]+|[\s.]+$', '' ` + -replace '[-.\s]+', '-' ` + | ForEach-Object { $_.ToLower().Substring(0, [Math]::Min($_.Length, $chars)) } + } +} \ No newline at end of file