Here is a function that can be used to quickly gather folder information about a user’s home folder.
There is one stipulation.
For this to work you must have the Quest Active Directory Snap-In configured for your Powershell session.
This will apply to users contained within an Microsoft Active Directory structure.
I have used the “^” in place of the “select-object” command. This is an alias that I use to make typing much faster. It is a symbol that I have never had a conflict on.
I have called the function GQUF. This is short for Get-QADUserFunction, but you may call it whatever you like of course.
Here is the syntax of the command. There are three options that are available when this command is run with the second command line switch.
“GQUF userid –groups” or
“GQUF userid -explorer” or
“GQUF userid –size.”
The –groups switch will detail all of the active directory groups in which the member is included.
The –explorer switch will open an explorer window pointed at the user’s home folder.
The –size switch will detail the total size of the user’s home folder.
Here is the code. See a screen shot at the bottom.
#*******************************
#This function looks up a user home drive and home directory
#Uses get-qaduser
function gquf
{
$UserID = $Args[0]
$Domain = $Args[1]
$result = Get-QADUser $Args[0] | Select-Object SamAccountName, homedirectory, homedrive, email, displayname # | ft -autosize
#$result | ft -autosize
Write-Host “Display Name:” $result.displayname -foregroundcolor green
Write-Host “Email Address:” $result.email -foregroundcolor green
Write-Host “HomeDir:” $result.homedrive $result.homedirectory -foregroundcolor green
Write-Host “”
Write-Host “Permissions for “$result.homedirectory -foregroundcolor Yellow
get-aclf $result.homedirectory
switch ($Args[1])
{
{$_ -eq “-groups”}
{
write-host “Member Of:”
(Get-QADUser $Args[0] | ^ memberof).memberof | sort
}
{$_ -eq “-explorer”}
{
explorer $result.homedirectory
}
{$_ -eq “-size”}
{
Write-Host “Calculating the size of the homefolder…” -foregroundcolor red
$fs New-Object -comobject Scripting.FileSystemObject
$tempSize $fs.GetFolder($result.homedirectory).size/1024/1024
$tempSize ‘{0:N}’ -f [double]$tempSize
Write-Host “$tempSize MB”
}
}
}
#*******************************
Here is the screen shot for the –size switch. Sensitive information has been blocked out.
Thank You,
Patrick