Files
Sandbox/HomeDrive.ps1
Zack Meier 03dba08135 sync
2026-04-15 15:42:41 -05:00

37 lines
997 B
PowerShell

try
{
$Filter = "(samaccountname=$env:username)"
$RootOU = "dc=nd,dc=gov"
Write-Warning $Filter
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.Filter = $Filter
$result=$Searcher.FindAll()
$homedir = $result.properties.homedirectory
$homedrive = $result.properties.homedrive
$ScriptPath = $result.properties.scriptpath
Write-Warning ("HomeDirectory: " + $homedir )
Write-Warning ("HomeDrive: " + $homedrive)
If($homedrive)
{
New-PSDrive -Name $homedrive.TrimEnd(':') -PSProvider FileSystem -Root $homedir -Persist
}
If($ScriptPath)
{
Write-Warning ("ScriptPath: " + $ScriptPath)
$LoginScript = "\\nd.gov\netlogon\$ScriptPath"
Start-Process "cmd.exe" "/c $loginscript" #<< run loginscript
}
}
catch
{
New-Item -Path "$env:userprofile\Desktop\MapDrivesError.txt"
$error | Set-Content .\MapDrivesError.txt
}
Read-Host -Prompt "Press Enter to complete"