I need to substitute a server address with a DFS one in each user's home directory. Unfortunately only a portion of the string is constant. Bellow is an attempt in Powershell that works but is clumsy. Is there a better way?
$hdir = (Get-ADUser bguest -Properties *).HomeDirectory
$hdir = $hdir -replace "\\\\.*\\", "\\\\ad.company.com\\lfl\\"
$hdir = $hdir -replace "\\", "-"
$hdir = $hdir -replace "--", "-"
$hdir = $hdir -replace "-", "`\"
Set-ADUser bguest -HomeDirectory $hdir
Any pointers are greatly appreciated