Public/Get-NativePath.ps1
<#
.SYNOPSIS This function creates a string with the proper Directory Seperator Character (either '\' or '/') depending on the Operating System. .DESCRIPTION See .SYNOPSIS .NOTES .PARAMETER PathAsStringArray This parameter is MANDATORY. This parameter takes an array of strings, each of which represent a directory along the path to a file or directory. .EXAMPLE # Open an elevated PowerShell Session, import the module, and - PS C:\Users\zeroadmin> Get-NativePath @("$HOME",'Documents','SubFolder','file.txt') #> function Get-NativePath { [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string[]]$PathAsStringArray ) $PathAsStringArray = foreach ($pathPart in $PathAsStringArray) { $SplitAttempt = $pathPart -split [regex]::Escape([IO.Path]::DirectorySeparatorChar) if ($SplitAttempt.Count -gt 1) { foreach ($obj in $SplitAttempt) { $obj } } else { $pathPart } } $PathAsStringArray = $PathAsStringArray -join [IO.Path]::DirectorySeparatorChar $PathAsStringArray } |