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
Thank you in advance for your help and time.
José
Answers (2)
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)
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é