Hello, due to more people teleworking this time of year an issue has been noticed and brought up that when connecting to our VPN the network drives are all there except for the home drive. I have created a short function that should and does find and map
the home drive for the local user when run on its own.
Function Map-HomeDrive
{
$adsearch = New-Object DirectoryServices.DirectorySearcher
$adsearch.Filter = '(&(objectCategory=person)(objectClass=user)('+"anr=$env:UserName"+'))'
$adsearch.SearchRoot = 'LDAP://DC=domain,DC=com'
$results = $adsearch.FindOne()
$object = [adsi]$results.path.ToString()
$directory = $object.HomeDirectory.ToString()
if (!(Get-PSDrive -Name U -ErrorAction SilentlyContinue)) {New-PSDrive -Name U -Root $directory -PSProvider FileSystem -Persist -ErrorAction SilentlyContinue}
}running Get-PSDrive -Name U afterwards results in a "Cannot Find drive" message
running the if (!(Get-PSDrive ... SilentlyContinue) line by itself does map the drive and makes it available to the user.
Does PowerShell not run the function in the same environment or is there some parameter I may be missing?
Primarily Windows 7 w/ PowerShell v3
thanks,
-Nick