/build/static/layout/Breadcrumb_cap_w.png

Can I find a User's Region using custom inventory fields?

Hi,

I tried to use Powershell within ShellCommandTextReturn() to get the user's region but I'm getting an error:

Missing closing '}' in statement block or type definition.

    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : MissingEndCurlyBrace

The script:

ShellCommandTextReturn(Powershell "invoke-command {if (Get-PSDrive HKU -ErrorAction SilentlyContinue) {""} else { New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | out-null};$usr = (Get-WmiObject -ClassName Win32_ComputerSystem).Username;$User = New-Object System.Security.Principal.NTAccount($usr);$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value;gp "HKU:\$($sid)\Control Panel\International\Geo\" | select -exp Name}") 

If I ran it within Powershell, the following script works:

if (Get-PSDrive HKU -ErrorAction SilentlyContinue) {""} else { New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | out-null};$usr=(Get-WmiObject -ClassName Win32_ComputerSystem).Username;$User = New-Object System.Security.Principal.NTAccount($usr);$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value;gp "HKU:\$($sid)\Control Panel\International\Geo\" | select -exp Name

Let me know what I'm missing or doing wrong, please.
Thank you in advance for your help and time.
José

0 Comments   [ + ] Show comments

Answers (2)

Posted by: Nico_K 1 year ago
Red Belt
0

A custom inventory rule runs as SYSTEM, you want to have info from the Hive of the Current User. You may need to run the script with the user in question locally (for instance in the scripting module) and then read out a file you created in a common folder (like c:\programdata\quest\kace\ownscripts or similar)

Posted by: joselguerra 1 year ago
White Belt
0

Hi Nico_K,


Thank you for your answer. I did a test opening Powershell as administrator, running the below script as admin, which in fact returns the logged in user's region correctly. However, it isn't running on the created Custom Inventory Field within Inventory, Software.

ShellCommandTextReturn(Powershell "invoke-command {if (Get-PSDrive HKU -ErrorAction SilentlyContinue) {""} else { New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | out-null};$usr = (Get-WmiObject -ClassName Win32_ComputerSystem).Username;$User = New-Object System.Security.Principal.NTAccount($usr);$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value;gp "HKU:\$($sid)\Control Panel\International\Geo\" | select -exp Name}") 

Any suggestions please?

Regards,

José

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ