Run powershell command or script for discovery pattern extension
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 10:42 PM
I'm attempting to run a powershell command to pull attributes. I created a extension to the Windows OS discovery pattern.
But, I'm not getting any results. Does anyone have any clear examples of getting this to work (powershell scripts or commands).
I followed instructions here, but it doesn't work.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0821628
----------------------------- Computer UUID ----------------------------- # REQUIRED VARIABLES $error.clear() Try { # DO WORK HERE $CompUUID = get-wmiobject Win32_ComputerSystemProduct -computername '.' | Select-Object -ExpandProperty UUID } Catch { $_ } ----------------------------- Domain Machine SID ----------------------------- # REQUIRED VARIABLES $error.clear() Try { # DO WORK HERE #use the computername followed by a $ sign to get the SID the domain gave the machine (should work offline as the machine keeps a copy) [string]$domainCompName = "$($env:COMPUTERNAME)$" $ID = New-Object System.Security.Principal.NTAccount($domainCompName) $IDTranslated = $ID.Translate([System.Security.Principal.SecurityIdentifier]) $DomainMachineSID = $IDTranslated.Value } Catch { $_ } -----------------------------
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2024 09:33 PM
Hello @Quan Nguyen,
Please refer to the below links:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0821628
If it is helpful, please mark it as helpful and accept the correct solution.
Thanks & Regards,
Abbas Shaik

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2024 10:08 PM
Is Above Code Snippet is working using Power shell Prompt from Mid Server?
Chck Powershell Access and execution on Target Host Server/IP |
$target = "<target_ip>" |
$userName = "<user_name>" |
$userPassword = "<user_password>" |
$securePasswd = ConvertTo-SecureString $userPassword -AsPlainText –Force |
$cred = New-Object System.Management.Automation.PSCredential ($userName, $securePasswd) |
$session = New-PSSession -ComputerName $target -Credential $cred -ConfigurationName Microsoft.PowerShell32 |
Enter-PSSession $session |
Invoke-Command -Session $session -FilePath c:\file_path\file_Name.ps1 |
Exit-PSSession |
Store your Script in given Path and file on mid server ..This is just a raw test.
Regards
RP