#File Format - Options
# txt - Table formated file
# csv - comma seperated file
$FType = "txt"
#List of Servers text file
$SPath = "D:\temp\Servers.txt"
#Output file - do not include extension
$FPath = "D:\temp\DatabaseRoles-1"
cls
# Delete output file if exist
If (Test-Path $FPath){
Remove-Item $FPath
}
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$FormatEnumerationLimit = -1
$SSASServerFile = Get-Content -Path $SPath
foreach ($line in $SSASServerFile)
{
write "------------------------------------------------------------------------------------------------------- $line"
# Try to connect to the SSAS server
$SSASServer = New-Object Microsoft.AnalysisServices.Server
$SSASServer.Connect($line)
#$line = New-Object Microsoft.AnalysisServices.Server
#$line.Connect($SSASServerName)
# Object to store the result
$Result = @()
# Get the SSAS databases and loop thru each of them
foreach ($DB in $SSASServer.Databases)
{
# Get the SSAS database
$SSASDatabase = $SSASServer.Databases.Item($DB.name)
foreach ($Role in $SSASDatabase.Roles)
{
$DatabasePermission = $DB.DatabasePermissions.GetByRole($Role.ID)
# Get the SSAS cubes within the database
foreach ($Cube in $DB.Cubes)
{
$CubePermission = $Cube.CubePermissions.GetByRole($Role.ID)
$ItemResult = New-Object System.Object
$ItemResult | Add-Member -type NoteProperty -name Server -value $SSASServer.Name
$ItemResult | Add-Member -type NoteProperty -name DatabaseName -value $DB.Name
$ItemResult | Add-Member -type NoteProperty -name RoleName -value $Role.Name
$ItemResult | Add-Member -type NoteProperty -name DatabaseAdministrator -value $DatabasePermission.Administer
$ItemResult | Add-Member -type NoteProperty -name DatabaseProcess -value $DatabasePermission.Process
$ItemResult | Add-Member -type NoteProperty -name DatabaseRead -value $DatabasePermission.Read
$ItemResult | Add-Member -type NoteProperty -name CubeName -value $Cube.Name
$ItemResult | Add-Member -type NoteProperty -name CubeRead -value $CubePermission.Read.value__
$ItemResult | Add-Member -type NoteProperty -name CubeWrite -value $CubePermission.Write.value__
$ItemResult | Add-Member -type NoteProperty -name CubeProcess -value $CubePermission.Process
#$ItemResult | Add-Member -type NoteProperty -name CubeReadDefinition_Local -value $CubePermission.ReadDefinition.value__
#$ItemResult | Add-Member -type NoteProperty -name CubeReadSourceData_Drillthrough -value $CubePermission.ReadSourceData.value__
$ItemResult | Add-Member -type NoteProperty -name RoleMembers -value ($Role.Members | Select -ExpandProperty Name)
$Result +=$ItemResult
#write $Result
}
}
}
if ($FType -eq "txt"){
$Result | Select Server, DatabaseName, RoleName, DatabaseAdministrator, CubeRead, CubeWrite, CubeProcess, RoleMembers | format-table * -Wrap -AutoSize | Out-file -Append "$FPath.txt" }
Else {
($Result | Select Server, DatabaseName, RoleName, DatabaseAdministrator, CubeRead, CubeWrite, CubeProcess, RoleMembers ) | Export-CSV -notype -Append "$FPath.csv" }
}
No comments:
Post a Comment