as

AppSense – Personalisierung: Datengröße pro Benutzer für eine Personalisierungsgruppe auslesen

Das folgende Skript liest die Daten pro Benutzer für eine dedizierte Personalisierungsgruppe aus und addiert diese zusammen. Die Abfrage findet direkt gegen die AppSense Personalisierungsdatenbank statt. Die Ausgabe ist eine csv Datei die Kommasepariert den Benutzernamen und die Datenmenge in Kilobyte angibt.

Beispiel:
user1,9478
user2,162
user3,1566
user4,2764

Unter Variablen muss die Personalisierungsgruppe, der Datenbankserver und der Datenbankname (Personalisierungsdatenbank) angegeben werden!

#-----Auslesen des Skriptpfad-----------------------------------------------
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
#---------------------------------------------------------------------------
#-----Variablen-------------------------------------------------------------
$global:PersonalizationGroupName = "PERSONALISIERUNGSGRUPPE"
$global:SQLServer = "DATENBANKSERVER\INSTANZ"
$global:DatabaseName = "DATENBANKNAME"
$global:cc_multi_output = ""
$global:PersonalizationGroupID = ""
$global:LogFile = Join-Path (Get-ScriptDirectory) "AppSense_Get.log"
#---------------------------------------------------------------------------
#-----Read user-------------------------------------------------------------
$logText = "{0:yyyy-MM-dd  HH-mm-ss} - No user file found" -f (Get-Date)
$userlist = Join-Path (Get-ScriptDirectory) "user.txt"
If (-NOT (test-path "$userlist")){$logText | out-file -Append $global:LogFile}
Else {$global:UserList = Get-Content $userlist}
#---------------------------------------------------------------------------
#-----Write user------------------------------------------------------------
$Global:UserOutList = Join-Path (Get-ScriptDirectory) "user_out.csv"
If (test-path $Global:UserOutList){remove-item $Global:UserOutList}
#---------------------------------------------------------------------------
#----Datenbankzugriff / Auslesen der Pakete / Ablage in Datei---------------
function fu_execute-sql-multi-output {
param (
[string]$dbserver,
[string]$db,
[string]$SQLCommand
)
#Connection to SQL-Server
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $dbserver; Database = $db; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SQLCommand
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$global:cc_multi_output = New-Object System.Data.DataSet
$SqlAdapter.Fill($global:cc_multi_output)
$SqlConnection.Close()
}
#---------------------------------------------------------------------------
#----Get Personalization Group ID-------------------------------------------
$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName "SELECT * FROM UserGroup where name = '$global:PersonalizationGroupName'"
$global:UserGroup = $global:cc_multi_output
$global:cc_multi_output = ""
foreach ($entry in $global:UserGroup.Tables[0]){
$global:PersonalizationGroupID = $global:UserGroup.Tables[0].Rows[0][0]
}
$logText = "{0:yyyy-MM-dd  HH-mm-ss} - GroupName: $global:PersonalizationGroupName / GroupID: $global:PersonalizationGroupID" -f (Get-Date)
$logText | out-file -Append $global:LogFile
#---------------------------------------------------------------------------
#----Get User IDs-----------------------------------------------------------
$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName "SELECT * FROM [User]"
$global:UserTable = $global:cc_multi_output
$global:cc_multi_output = ""
#---------------------------------------------------------------------------
#----Get Application Profile Data-------------------------------------------
$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName "SELECT * FROM ApplicationProfile"
$global:ApplicationProfileTable = $global:cc_multi_output
$global:cc_multi_output = ""
#---------------------------------------------------------------------------
#----Get user data size-----------------------------------------------------
$h = 0
$global:Size = 0
foreach ($entry in $global:UserTable.Tables[0]){
$userPK = $global:UserTable.Tables[0].Rows[$h][0]
$userName = $global:UserTable.Tables[0].Rows[$h][10]
$i = 0
$global:Size = 0
$global:InMigration = 0
foreach ($entry1 in $global:ApplicationProfileTable.Tables[0]){
$userFK = $global:ApplicationProfileTable.Tables[0].Rows[$i][0]

If ($userFK -eq $userPK){
$UserGroupFK = $global:ApplicationProfileTable.Tables[0].Rows[$i][1]
If ($global:PersonalizationGroupID -eq $UserGroupFK){
$global:InMigration = 1
$StoredSize = $global:ApplicationProfileTable.Tables[0].Rows[$i][9]
If ([string]::IsNullOrEmpty($StoredSize)){$StoredSize = 0}
$global:Size = $global:Size + $StoredSize
}
}
$i++
}
$h++
If ($global:InMigration -eq 1){
[INT]$SizeInKB = $global:Size / 1024
$OutText = "$userName,$SizeInKB"
$OutText | out-file -Append $Global:UserOutList
write-host $OutText
}
}

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *