
<# Task was to create a script that can pull out all user within the group xxxx who have the file xxxx in this path 
\\bhx1sv-dm1\wf1a_cif0\user_data\userstore\Redirect\<username>\AppData\Roaming\SoftGrid Client\INTEGRTY.106-AE22DB3A-8830-4E67\aecuk_sg_integrity
Created By Alberto Igbinedion
Thanks to Adam Beardwood
#>
#Check that Exchange Snap-in is added if not add it
$snaps = Get-PSSnapin
foreach($snap in $snaps){if($snap.name -eq "Microsoft.Exchange.Management.PowerShell.E2010"){$exflag = 1}}
if($exflag -ne 1){Add-PSSnapin -name Microsoft.Exchange.Management.PowerShell.E2010}


#Get All The group members including groups within the group  aecuk_sg_integrity

$groupmembers = Get-ADGroupMember -identity "aecuk_sg_integrity"  -recursive | select samaccountname

#Get Details of the file UsrVol_sftfs_v1.pkg for every samaccountname of the groups aecuk_sg_integrity #(groupmembers result)

foreach($member in $groupmembers) {

try{
	$find = get-item "\\bhx1sv-dm1\wf1a_cif0\user_data\userstore\Redirect\$($member.samaccountname)\AppData\Roaming\SoftGrid Client\INTEGRTY.106-AE22DB3A-8830-4E67\UsrVol_sftfs_v1.pkg" -erroraction stop
}catch{
write-host "File not found for $($member.samaccountname)"
}

#From The result of $find get the size in Megabyte 1024/1024 of the files found ; if needed in kilobyte 1024 

$length = $find.length/1024/1024

# Write the result from $find including the size $length to root folder file name \Citrixusers.csv 

write-host "$($member.samaccountname) - $length" 

"$($member.samaccountname),$length" | Out-File ".\Citrixusers.csv" -append
}