Skip to content

Commit

Permalink
Merge pull request #13 from PluginsOCSInventory-NG/reworkpowershell
Browse files Browse the repository at this point in the history
Rework agent plugin in powershell
  • Loading branch information
gillesdubois authored Apr 15, 2020
2 parents 27fece0 + b97a13d commit ab81eab
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 113 deletions.
2 changes: 2 additions & 0 deletions APACHE/Map.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fields => {
SIZE => {},
LASTLOGON => {},
DESCRIPTION => {},
USERMAYCHANGEPWD => {},
PASSWORDEXPIRES => {},
STATUS => {},
SID => {}
}
Expand Down
48 changes: 48 additions & 0 deletions agent/winusers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function Get-AdminUser {
param([string] $username)
$admingroup = Get-LocalGroupMember -Group "Administrateurs"
$userType = "Local user"

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

return $userType
}

function Get-Size
{
param([string]$pth)
write-host $pth
"{0:n2}" -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1mb)
}


$users = Get-LocalUser | Select *

foreach ($user in $users) {
if($user.Name -ne $null){

$userType = Get-AdminUser $user.Name
$path = "C:\Users\"+ $user.Name
$folderSize = Get-Size $path
if($user.Enabled -ne "False") { $userStatus = "Disabled" } else { $userStatus = "Enabled" }

$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"
}
}

Write-Host $xml
112 changes: 0 additions & 112 deletions agent/winusers.vbs

This file was deleted.

2 changes: 2 additions & 0 deletions cd_winusers/cd_winusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
'Last logon' => 'lastlogon',
'Description' => 'description',
'Status' => 'status',
'Change Password' => 'usermaychangepwd'
'Password expires' => 'passwordexpires'
'Sid' => 'sid'
);
$list_col_cant_del=$list_fields;
Expand Down
7 changes: 6 additions & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ function extension_install_winusers()
{
$commonObject = new ExtensionCommon;

$commonObject -> sqlQuery("CREATE TABLE IF NOT EXISTS `winusers` (
// Drop table first
$commonObject -> sqlQuery("DROP TABLE `winusers`;");

$commonObject -> sqlQuery("CREATE TABLE `winusers` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`HARDWARE_ID` INT(11) NOT NULL,
`NAME` VARCHAR(255) DEFAULT NULL,
Expand All @@ -16,6 +19,8 @@ function extension_install_winusers()
`LASTLOGON` VARCHAR(255) DEFAULT NULL,
`DESCRIPTION` VARCHAR(255) DEFAULT NULL,
`STATUS` VARCHAR(255) DEFAULT NULL,
`USERMAYCHANGEPWD` VARCHAR(255) DEFAULT NULL,
`PASSWORDEXPIRES` VARCHAR(255) DEFAULT NULL,
`SID` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`ID`,`HARDWARE_ID`)
) ENGINE=InnoDB ;");
Expand Down

0 comments on commit ab81eab

Please sign in to comment.