0

I have a csv file with users (domain\user) that I need to find their access. I found a good link here (Powershell script to find permissions for a specific user) on SP Forum. I am calling the function with following code but it only works if I have only one user in the csv file. If I have multiple users in the csv file then it stops. Any idea why?

$usercsv = import-csv 'C:\\Powershell\\MigrationRelated\\ADGroups.csv'
$webApp = "http://inside.NOVIntranet.com"

foreach($ADusers in $usercsv)
 {
    $NOVUser = $ADusers.NOVGroup.Tostring() 
    GetUserAccessReport $webApp $NOVUser 
 }
  • did you try to print user name before calling the Getuser access report? – Waqas Sarwar MVP Sep 10 '14 at 15:20
  • I think my code is good. It's the output file being regenerated for each user therefore overwriting the previous file. hmm. I think I need to declare the file at the top in the function then just write to it. Not sure. Any help will be appreciated. – Amber Berg Sep 10 '14 at 15:24
  • what happen with multiple user...its shows 1st user only or last user...or no user at all – Waqas Sarwar MVP Sep 10 '14 at 15:29
  • since file is overwritten so last user permissions info shows up in the output file. I ran multiple scenarios with single users, flipped users in the source csv file and all gave me same result. only the last processed users information is in the output csv file. hope this help. – Amber Berg Sep 10 '14 at 15:31
  • I tried -NoClobber but it does not help. I tried -Append -NoClobber and same thing. What else should I try? – Amber Berg Sep 10 '14 at 16:33
0

that's how i did, i just did for farm admin group you have to modify for others as well.:

Declare this on top

$results = @()
$fileLocation = "C:\user.csv

then in your Check before out-put csv

if($user.LoginName -eq $SearchUser){

$output = New-Object PSObject
$output | Add-Member NoteProperty -name Url -Value $AdminWebApp.URL
$output | Add-Member NoteProperty -name Title -Value $AdminSite.Title
"$($AdminWebApp.URL) `t Farm `t $($AdminSite.Title)`t Farm Administrator `t Farm Administrator"
$results += $output
}

at the end

$results | Export-Csv $fileLocation -NoTypeInformation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.