Hello all,
I am trying to write a script to update our home-drives in AD to a new location but I need the last part of the string not including the first back-slash, like this:
\\servername\users$\myusername
I would like to store the myusername part in a variable so that I can use it to construct the new home-drive location:
\\newserver\users$\myusername
Please could I have some assistance.
Thanks very much. This is what I have produced so far:
#Add snap-in and connect to domain
Add-PSSnapin Quest.ActiveRoles.ADManagement | Out-Null
Connect-QADService 'domain.co.uk' | Out-Null
#Get users with home drive we wish to change
$Users = Get-QADUser -SizeLimit 0 -SearchRoot 'DC=domain,DC=co,DC=uk' -SearchScope Subtree | Where {$_.HomeDirectory -like '\\servername*'}
#Go through each user, setting new home drive
ForEach($User in $Users)
{
$OriginalHomeDrive = $User.homeDirectory
#Split $OriginalHomeDrive to just username ???
$SAMAccountName = $User.SAMAccountName
Set-QADUser -Identity $SAMAccoutName -HomeDrive "M:" -HomeDirectory "\\newserver\users$\$myusername" -proxy -whatif
}