{"id":1944,"date":"2016-11-27T16:29:14","date_gmt":"2016-11-27T14:29:14","guid":{"rendered":"http:\/\/workplace.skyworker.de\/?p=1944"},"modified":"2023-08-22T10:39:17","modified_gmt":"2023-08-22T08:39:17","slug":"appsense-personalisierung-datengroesse-pro-benutzer-fuer-eine-personalisierungsgruppe-auslesen","status":"publish","type":"post","link":"http:\/\/workplace.skyworker.de\/?p=1944","title":{"rendered":"AppSense &#8211; Personalisierung: Datengr\u00f6\u00dfe pro Benutzer f\u00fcr eine Personalisierungsgruppe auslesen"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"1944\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">0    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"1944\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\">0<\/span>\r\n<\/div><\/div><p style=\"text-align: justify;\">Das folgende Skript liest die Daten pro Benutzer f\u00fcr 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.<\/p>\n<p style=\"text-align: justify;\"><!--more-->Beispiel:<br \/>\nuser1,9478<br \/>\nuser2,162<br \/>\nuser3,1566<br \/>\nuser4,2764<\/p>\n<p style=\"text-align: justify;\">Unter Variablen muss die Personalisierungsgruppe, der Datenbankserver und der Datenbankname (Personalisierungsdatenbank) angegeben werden!<\/p>\n<p>[ps]<br \/>\n#&#8212;&#8211;Auslesen des Skriptpfad&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nfunction Get-ScriptDirectory {<br \/>\n$Invocation = (Get-Variable MyInvocation -Scope 1).Value<br \/>\nSplit-Path $Invocation.MyCommand.Path<br \/>\n}<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;&#8211;Variablen&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n$global:PersonalizationGroupName = &quot;PERSONALISIERUNGSGRUPPE&quot;<br \/>\n$global:SQLServer = &quot;DATENBANKSERVER\\INSTANZ&quot;<br \/>\n$global:DatabaseName = &quot;DATENBANKNAME&quot;<br \/>\n$global:cc_multi_output = &quot;&quot;<br \/>\n$global:PersonalizationGroupID = &quot;&quot;<br \/>\n$global:LogFile = Join-Path (Get-ScriptDirectory) &quot;AppSense_Get.log&quot;<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;&#8211;Read user&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n$logText = &quot;{0:yyyy-MM-dd\u00a0 HH-mm-ss} &#8211; No user file found&quot; -f (Get-Date)<br \/>\n$userlist = Join-Path (Get-ScriptDirectory) &quot;user.txt&quot;<br \/>\nIf (-NOT (test-path &quot;$userlist&quot;)){$logText | out-file -Append $global:LogFile}<br \/>\nElse {$global:UserList = Get-Content $userlist}<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;&#8211;Write user&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n$Global:UserOutList = Join-Path (Get-ScriptDirectory) &quot;user_out.csv&quot;<br \/>\nIf (test-path $Global:UserOutList){remove-item $Global:UserOutList}<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;-Datenbankzugriff \/ Auslesen der Pakete \/ Ablage in Datei&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nfunction fu_execute-sql-multi-output {<br \/>\nparam (<br \/>\n[string]$dbserver,<br \/>\n[string]$db,<br \/>\n[string]$SQLCommand<br \/>\n)<br \/>\n#Connection to SQL-Server<br \/>\n$SqlConnection = New-Object System.Data.SqlClient.SqlConnection<br \/>\n$SqlConnection.ConnectionString = &quot;Server = $dbserver; Database = $db; Integrated Security = True&quot;<br \/>\n$SqlCmd = New-Object System.Data.SqlClient.SqlCommand<br \/>\n$SqlCmd.CommandText = $SQLCommand<br \/>\n$SqlCmd.Connection = $SqlConnection<br \/>\n$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter<br \/>\n$SqlAdapter.SelectCommand = $SqlCmd<br \/>\n$global:cc_multi_output = New-Object System.Data.DataSet<br \/>\n$SqlAdapter.Fill($global:cc_multi_output)<br \/>\n$SqlConnection.Close()<br \/>\n}<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;-Get Personalization Group ID&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName &quot;SELECT * FROM UserGroup where name = &#8218;$global:PersonalizationGroupName&#8217;&quot;<br \/>\n$global:UserGroup = $global:cc_multi_output<br \/>\n$global:cc_multi_output = &quot;&quot;<br \/>\nforeach ($entry in $global:UserGroup.Tables[0]){<br \/>\n$global:PersonalizationGroupID = $global:UserGroup.Tables[0].Rows[0][0]<br \/>\n}<br \/>\n$logText = &quot;{0:yyyy-MM-dd\u00a0 HH-mm-ss} &#8211; GroupName: $global:PersonalizationGroupName \/ GroupID: $global:PersonalizationGroupID&quot; -f (Get-Date)<br \/>\n$logText | out-file -Append $global:LogFile<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;-Get User IDs&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName &quot;SELECT * FROM [User]&quot;<br \/>\n$global:UserTable = $global:cc_multi_output<br \/>\n$global:cc_multi_output = &quot;&quot;<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;-Get Application Profile Data&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n$cc_output_count = fu_execute-sql-multi-output $global:SQLServer $global:DatabaseName &quot;SELECT * FROM ApplicationProfile&quot;<br \/>\n$global:ApplicationProfileTable = $global:cc_multi_output<br \/>\n$global:cc_multi_output = &quot;&quot;<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#&#8212;-Get user data size&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n$h = 0<br \/>\n$global:Size = 0<br \/>\nforeach ($entry in $global:UserTable.Tables[0]){<br \/>\n$userPK = $global:UserTable.Tables[0].Rows[$h][0]<br \/>\n$userName = $global:UserTable.Tables[0].Rows[$h][10]<br \/>\n$i = 0<br \/>\n$global:Size = 0<br \/>\n$global:InMigration = 0<br \/>\nforeach ($entry1 in $global:ApplicationProfileTable.Tables[0]){<br \/>\n$userFK = $global:ApplicationProfileTable.Tables[0].Rows[$i][0]<\/p>\n<p>If ($userFK -eq $userPK){<br \/>\n$UserGroupFK = $global:ApplicationProfileTable.Tables[0].Rows[$i][1]<br \/>\nIf ($global:PersonalizationGroupID -eq $UserGroupFK){<br \/>\n$global:InMigration = 1<br \/>\n$StoredSize = $global:ApplicationProfileTable.Tables[0].Rows[$i][9]<br \/>\nIf ([string]::IsNullOrEmpty($StoredSize)){$StoredSize = 0}<br \/>\n$global:Size = $global:Size + $StoredSize<br \/>\n}<br \/>\n}<br \/>\n$i++<br \/>\n}<br \/>\n$h++<br \/>\nIf ($global:InMigration -eq 1){<br \/>\n[INT]$SizeInKB = $global:Size \/ 1024<br \/>\n$OutText = &quot;$userName,$SizeInKB&quot;<br \/>\n$OutText | out-file -Append $Global:UserOutList<br \/>\nwrite-host $OutText<br \/>\n}<br \/>\n}<br \/>\n[\/ps]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>0 0 Das folgende Skript liest die Daten pro Benutzer f\u00fcr 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.<\/p>\n","protected":false},"author":1,"featured_media":1943,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[115,116],"tags":[117,119,118,120],"_links":{"self":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/1944"}],"collection":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1944"}],"version-history":[{"count":5,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/1944\/revisions"}],"predecessor-version":[{"id":1951,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/1944\/revisions\/1951"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/media\/1943"}],"wp:attachment":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}