[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Using Get-SPSite
function global:Get-SPSite($url)
{
return new-Object Microsoft.SharePoint.SPSite($url)
}
function global:Get-SPWeb($url)
{
$site= New-Object Microsoft.SharePoint.SPSite($url)
if($site -ne $null)
{
$web=$site.OpenWeb();
}
return $web
}
$URL="http://usdttdevbq007/"
$site = Get-SPSite $URL
#Write the Header to "Tab Separated Text File"
"Site Name`t URL `t Group Name `t User Name`t Type `t Permission Levels `t Group ID" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"
#Iterate through all Webs
foreach ($web in $site.AllWebs)
{
#Write-Host "Site: ":$web -ForegroundColor Red;
#Write the Header to "Tab Separated Text File"
"$($web.title) `t $($web.URL) `t `t `t `t `t `t `t `t `t `t " | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
$siteUsers = $web.SiteUsers
$siteUsers.Count
foreach($WebRoleAssignment in $Web.RoleAssignments )
{
$plevel=@()
$plevel = $WebRoleAssignment.RoleDefinitionBindings
#Write-Host $plevel.Name
$UserGroupName=$WebRoleAssignment.Member.Name
if($WebRoleAssignment.Member.GetType() -eq [Microsoft.SharePoint.SPGroup])
{
$Type="Group"
$UserName=$WebRoleAssignment.Member.Name
#Set Flag value for "Group Exists"
$GroupExistsFlag=$true
}
else
{
#$Typeis = $WebRoleAssignment.Member.GetType()
$DirectUser = "User"
$UserName=$WebRoleAssignment.Member.Name
#Write-Host "permission levels: ": $RoleDefinition.Name
foreach($roleDefinition in $WebRoleAssignment.RoleDefinitionBindings)
{
"`t `t `t $($UserName) `t $($DirectUser) `t $($plevel.Name) `t" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
}
#Is it a Domain Group?
if($WebRoleAssignment.Member.IsDomainGroup)
{
$Type="Domain Group"
}
else #if($WebRoleAssignment.Member.LoginName)
{
$Type="User"
}
}
}
#Get all Groups and Iterate through
foreach ($group in $Web.groups)
{
$Groupidis= $group.ID
$GroupPlevel=@()
$GroupPlevel= $group.Roles
#Write-Host $GroupPlevel.Name
$GroupNameis ="Group"
"`t `t $($Group.Name) `t `t $($GroupNameis) `t $($GroupPlevel) `t $($Groupidis)" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
#Iterate through Each User in the group
foreach ($user in $group.users)
{
$Usernameis ="User in Group"
"`t `t `t $($user.name)`t $($Usernameis) `t `t" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
#Write-Host "Groups: ":$user -ForegroundColor white;
#Exclude Built-in User Accounts
#if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
#{
#}
}
}
}
#write-host "Report Generated at C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"
Results:
#Using Get-SPSite
function global:Get-SPSite($url)
{
return new-Object Microsoft.SharePoint.SPSite($url)
}
function global:Get-SPWeb($url)
{
$site= New-Object Microsoft.SharePoint.SPSite($url)
if($site -ne $null)
{
$web=$site.OpenWeb();
}
return $web
}
$URL="http://usdttdevbq007/"
$site = Get-SPSite $URL
#Write the Header to "Tab Separated Text File"
"Site Name`t URL `t Group Name `t User Name`t Type `t Permission Levels `t Group ID" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"
#Iterate through all Webs
foreach ($web in $site.AllWebs)
{
#Write-Host "Site: ":$web -ForegroundColor Red;
#Write the Header to "Tab Separated Text File"
"$($web.title) `t $($web.URL) `t `t `t `t `t `t `t `t `t `t " | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
$siteUsers = $web.SiteUsers
$siteUsers.Count
foreach($WebRoleAssignment in $Web.RoleAssignments )
{
$plevel=@()
$plevel = $WebRoleAssignment.RoleDefinitionBindings
#Write-Host $plevel.Name
$UserGroupName=$WebRoleAssignment.Member.Name
if($WebRoleAssignment.Member.GetType() -eq [Microsoft.SharePoint.SPGroup])
{
$Type="Group"
$UserName=$WebRoleAssignment.Member.Name
#Set Flag value for "Group Exists"
$GroupExistsFlag=$true
}
else
{
#$Typeis = $WebRoleAssignment.Member.GetType()
$DirectUser = "User"
$UserName=$WebRoleAssignment.Member.Name
#Write-Host "permission levels: ": $RoleDefinition.Name
foreach($roleDefinition in $WebRoleAssignment.RoleDefinitionBindings)
{
"`t `t `t $($UserName) `t $($DirectUser) `t $($plevel.Name) `t" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
}
#Is it a Domain Group?
if($WebRoleAssignment.Member.IsDomainGroup)
{
$Type="Domain Group"
}
else #if($WebRoleAssignment.Member.LoginName)
{
$Type="User"
}
}
}
#Get all Groups and Iterate through
foreach ($group in $Web.groups)
{
$Groupidis= $group.ID
$GroupPlevel=@()
$GroupPlevel= $group.Roles
#Write-Host $GroupPlevel.Name
$GroupNameis ="Group"
"`t `t $($Group.Name) `t `t $($GroupNameis) `t $($GroupPlevel) `t $($Groupidis)" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
#Iterate through Each User in the group
foreach ($user in $group.users)
{
$Usernameis ="User in Group"
"`t `t `t $($user.name)`t $($Usernameis) `t `t" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
#Write-Host "Groups: ":$user -ForegroundColor white;
#Exclude Built-in User Accounts
#if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
#{
#}
}
}
}
#write-host "Report Generated at C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"
Results:
No comments:
Post a Comment