Find homedirectory absolute path and work with that path

82 Views Asked by At

I am fairly new to Powershell and have been googling for a solution for weeks now. I am looking for a way to find the absolute path of a homedirectory and work with that path. We have homedirectories on several servers. These homedirs are not always on the same drive, some servers use the D and others the E drive for this (I am not allowed to change this). When users leave company I have to move their homedir to a DeletedUsers folder. AD only shows the relative path of the homedir, not the absolute path. I am finding a way to do a search on the server (I can get the servername from the relative path) for the homedir folder.

$Homedirectory = get-aduser $Username -properties Homedirectory |Select-Object -ExpandProperty Homedirectory
$Server = $Homedirectory.split('\')[2]

This is what I have to search for all drives on the server.

$AllDrives = get-PSdrive -PSProvider 'FileSystem'
$NameToFind = "*$Username$*"
$Homedirectory = Get-ChildItem -Path $AllDrives -Filter $username -Recurse -Directory

It does not give me an error, but it also does not give me a path.

Hope someone can shed some light on this, thank you!

0

There are 0 best solutions below