Skip to content

Commit

Permalink
Merge pull request #25 from PluginsOCSInventory-NG/fixgetsize
Browse files Browse the repository at this point in the history
Fix Get-Size error
  • Loading branch information
gillesdubois authored Sep 16, 2021
2 parents 1882b2a + f9f0d80 commit 93c2bf2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
46 changes: 25 additions & 21 deletions agent/winusers.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function Get-AdminUser {
param([string] $username)
$admingroup = Get-LocalGroupMember -SID "S-1-5-32-544"
$userType = "Local user"
$userType = "Local"

foreach ($admin in $admingroup) {
$name = $admin.name -split "\\"
if($name[1] -eq $username){
$userType = "Admin user"
$userType = "Admin"
}
}

Expand All @@ -16,10 +16,13 @@ function Get-AdminUser {
function Get-Size
{
param([string]$pth)
"{0:n2}" -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1mb)
try {
"{0:n2}" -f ((gci -path $pth -recurse -ErrorAction Ignore | measure-object -ErrorAction Stop -property length -sum).sum /1mb)
} catch {
"{0:n2}" -f 0
}
}


$users = Get-LocalUser | Select *
$pathUsers = "C:\Users"
$allUsers = @()
Expand All @@ -31,18 +34,19 @@ foreach ($user in $users) {
$path = "C:\Users\"+ $user.Name
$folderSize = Get-Size $path
if($user.Enabled -ne "False") { $userStatus = "Disabled" } else { $userStatus = "Enabled" }

$xml += "<WINUSERS>"
$xml += "<NAME>"+ $user.Name +"</NAME>"
$xml += "<TYPE>"+ $userType +"</TYPE>"
$xml += "<SIZE>"+ $folderSize +"</SIZE>"
$xml += "<LASTLOGON>"+ $user.LastLogon +"</LASTLOGON>"
$xml += "<DESCRIPTION>"+ $user.Description +"</DESCRIPTION>"
$xml += "<STATUS>"+ $userStatus +"</STATUS>"
$xml += "<USERMAYCHANGEPWD>"+ $user.UserMayChangePassword +"</USERMAYCHANGEPWD>"
$xml += "<PASSWORDEXPIRES>"+ $user.PasswordExpires +"</PASSWORDEXPIRES>"
$xml += "<SID>"+ $user.SID +"</SID>"
$xml += "</WINUSERS>"
if($userType -eq "Local") { $userType = $user.PrincipalSource }

$xml += "<WINUSERS>`n"
$xml += "<NAME>"+ $user.Name +"</NAME>`n"
$xml += "<TYPE>"+ $userType +"</TYPE>`n"
$xml += "<SIZE>"+ $folderSize +"</SIZE>`n"
$xml += "<LASTLOGON>"+ $user.LastLogon +"</LASTLOGON>`n"
$xml += "<DESCRIPTION>"+ $user.Description +"</DESCRIPTION>`n"
$xml += "<STATUS>"+ $userStatus +"</STATUS>`n"
$xml += "<USERMAYCHANGEPWD>"+ $user.UserMayChangePassword +"</USERMAYCHANGEPWD>`n"
$xml += "<PASSWORDEXPIRES>"+ $user.PasswordExpires +"</PASSWORDEXPIRES>`n"
$xml += "<SID>"+ $user.SID +"</SID>`n"
$xml += "</WINUSERS>`n"

$allUsers += $user.Name
}
Expand All @@ -61,11 +65,11 @@ foreach ($userAd in $usersAd) {
$path = "C:\Users\"+ $userAd
$folderSize = Get-Size $path

$xml += "<WINUSERS>"
$xml += "<NAME>"+ $userAd +"</NAME>"
$xml += "<TYPE>Domain user</TYPE>"
$xml += "<SIZE>"+ $folderSize +"</SIZE>"
$xml += "</WINUSERS>"
$xml += "<WINUSERS>`n"
$xml += "<NAME>"+ $userAd +"</NAME>`n"
$xml += "<TYPE>Domain</TYPE>`n"
$xml += "<SIZE>"+ $folderSize +"</SIZE>`n"
$xml += "</WINUSERS>`n"
}

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Expand Down
4 changes: 2 additions & 2 deletions infos.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"displayName" : "Winusers",
"author" : ["J.C.BELLAMY"],
"contributor" : ["Guillaume PRIOU", "Gilles DUBOIS", "Rudy LAURENT"],
"contributor" : ["Guillaume PRIOU", "Gilles DUBOIS", "Rudy LAURENT", "Charlene AUGER"],
"supportedAgent" : ["Windows"],
"version" : "3.1",
"version" : "3.2",
"licence" : "GPLv2",
"description" : {
"fr" : "Remonte les utilisateurs Windows",
Expand Down

0 comments on commit 93c2bf2

Please sign in to comment.