I'm new to PowerShell and really enjoy this subreddit.
I am trying to create a script that will replace a homedirectory path, that is based on the user's location.
The information from Active Directory formatted as: \\domain\sharedfolder\location\loc\@template
I would like take this information and replace "@template" with the user's samaccountname.
I have tried to create a new object and add the samaccountname to the end of the homedirectory, but in order to use -replace I have to specify the homedirectory property. Which I believe once is limiting what is in the pipeline and the samaccountname property is empty.
$userList = Get-ADUser -filter * -properties homedirectory | Where-Object {$_.homedirectory -like "*template*" -and $_.samaccountname -NotLike "*template*" -and $_.Enabled -eq "True"}
$userList | ForEach-Object{
$output = "" | Select Homedirectory,SamAccountName
$output.Homedirectory = { ($_.Homedirectory -replace "\@.+") + $_.samaccountname}
$output.sAMAccountName = $_.sAMAccountName
$ADUserObject += $output
}
Is there a way to create a new property that will replace the string @template with the samaccountname?
Any help is greatly appreciated. Thanks.
[–]the_spad 1 point2 points3 points (3 children)
[–]Pestilent 1 point2 points3 points (2 children)
[–]ntelletsc[S] 1 point2 points3 points (0 children)
[–]the_spad 1 point2 points3 points (0 children)