Friday, September 21, 2018

I gotta split

#Locate the last split value in this case a folder from a path of unknown length.

$UserProfile = $env:USERPROFILE

#This item splits up the user profile into any given number items using the \ character as the charcter to split at.
$UserProfileSplit = $UserProfile.Split("\")

#The counts the number of split items generated in to the $UserProfileSplit array
$UserProfileSplit | measure | select -expand count


$UserProfileFolder = $UserProfileSplit | select -last 1