K1000 Custom Inventory Rule for Local Accounts
We are trying to create a custom inventory rule that will display the user and the users Full name. We have been successfull getting the user name to show up with this:
ShellCommandTextReturn(cmd /c net localgroup Users)
But appears we also need to have the user full name to show up also. Any suggestions on this?
Answers (2)
wmic useraccount where"LocalAccount=TRUE" get * /format:List
gn_admin is indeed a local adminaccount on my VM.
IF you want just specificcolumns, you could do:
wmic useraccount where"LocalAccount=TRUE" get Name,Disabled /format:List
Basically just replace * with acomma-seperated list of available columns to choose from.
Here’s a way to omit out some ofthe standard accounts too:
wmic useraccount where"LocalAccount=TRUE AND not Description like '%Guest%'" get */format:list
I was able to get this done with a powershell script. Thanks for looking.
Comments:
-
can you please share you powershell script with me i am in the process of doing the same thing - brighstarcuit 10 years ago
-
#---------------------------------------------------------------------------------
#The sample scripts are not supported under any Microsoft standard support
#program or service. The sample scripts are provided AS IS without warranty
#of any kind. Microsoft further disclaims all implied warranties including,
#without limitation, any implied warranties of merchantability or of fitness for
#a particular purpose. The entire risk arising out of the use or performance of
#the sample scripts and documentation remains with you. In no event shall
#Microsoft, its authors, or anyone else involved in the creation, production, or
#delivery of the scripts be liable for any damages whatsoever (including,
#without limitation, damages for loss of business profits, business interruption,
#loss of business information, or other pecuniary loss) arising out of the use
#of or inability to use the sample scripts or documentation, even if Microsoft
#has been advised of the possibility of such damages
#---------------------------------------------------------------------------------
#requires -Version 2.0
<#
.SYNOPSIS
This script can be list all of local user account.
.DESCRIPTION
This script can be list all of local user account.
.PARAMETER <AccountName>
Specifies the local user account you want to search.
.PARAMETER <ComputerName <string[]>
Specifies the computers on which the command runs. The default is the local computer.
.PARAMETER <Credential>
Specifies a user account that has permission to perform this action.
.EXAMPLE
C:\PS> C:\Script\GetLocalAccount.ps1
This example shows how to list all of local users on local computer.
.EXAMPLE
C:\PS> C:\Script\GetLocalAccount.ps1 | Export-Csv -Path "D:\LocalUserAccountInfo.csv" -NoTypeInformation
This example will export report to csv file. If you attach the <NoTypeInformation> parameter with command, it will omit the type information
from the CSV file. By default, the first line of the CSV file contains "#TYPE " followed by the fully-qualified name of the object type.
.EXAMPLE
C:\PS> C:\Script\GetLocalAccount.ps1 -AccountName "Administrator","Guest"
This example shows how to list local Administrator and Guest account information on local computer.
.EXAMPLE
C:\PS> $Cre=Get-Credential
C:\PS> C:\Script\GetLocalAccount.ps1 -Credential $Cre -Computername "WINSERVER"
This example lists all of local user accounts on the WINSERVER remote computer.
#>
Param
(
[Parameter(Position=0,Mandatory=$false)]
[ValidateNotNullorEmpty()]
[Alias('cn')][String[]]$ComputerName=$Env:COMPUTERNAME,
[Parameter(Position=1,Mandatory=$false)]
[Alias('un')][String[]]$AccountName,
[Parameter(Position=2,Mandatory=$false)]
[Alias('cred')][System.Management.Automation.PsCredential]$Credential
)
$Obj = @()
Foreach($Computer in $ComputerName)
{
If($Credential)
{
$AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
-Filter "LocalAccount='$True'" -ComputerName $Computer -Credential $Credential -ErrorAction Stop
}
else
{
$AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
-Filter "LocalAccount='$True'" -ComputerName $Computer -ErrorAction Stop
}
Foreach($LocalAccount in $AllLocalAccounts)
{
$Object = New-Object -TypeName PSObject
$Object|Add-Member -MemberType NoteProperty -Name "Name" -Value $LocalAccount.Name
$Object|Add-Member -MemberType NoteProperty -Name "Full Name" -Value $LocalAccount.FullName
$Obj+=$Object
}
If($AccountName)
{
Foreach($Account in $AccountName)
{
$Obj|Where-Object{$_.Name -like "$Account"}
}
}
else
{
$Obj
}
} - revsmitty 10 years ago
___________________________
ShellCommandTextReturn(net localgroup Administrators)
returns the information in the custom inventory area of a computer. - Jbr32 10 years ago