Loading
Using Powershell at scan - Example: Scanning Displays

Hi,

I want to integrate some powershell scripts in snow agent scan. 

I know where to locate the scripts and I think I understood the Integrity issue.

But how to get data to Inventory server? What output is needed to create new hardware or software? Is there any example to understand the correct way?

What about the ExecutionPolicy?

Thank you for your help. 

Update: Think I did it with many help. Thank you.


  • Community Manager (Flexera Software)

    Hi ‌, I have pulled in some information from user guides and given a example of steps to take to get data from PowerShell and post to a registry entry. Script Execution Policy   Snow Inventory Agent: PowerShell Extension scripts are standard PowerShell scripts with the restriction that you cannot load additional scripts if it goes against the current script execution policy on the machine running the script. PowerShell’s default script execution policy doesn’t impact scripts written exclusively for Snow Inventory: PowerShell Extension. PowerShell scripts that are not created by Snow Software are executed with low integrity. The low integrity mode prevents users from creating scripts that could potentially harm the system. With low integrity set the scripts cannot modify the underlying system. If you need to execute code on a local administrator level the PowerShell script needs to be digitally signed by Snow in order for our agent to execute. Deploying PowerShell Scripts   Snow Inventory Agent looks for PowerShell script files (*.ps1) beginning with the prefix Scan- in the following locations (relative to the running executable) when performing a scan: Any file that matches the pattern Scan-*.ps1 is executed as part of the inventory process. Example Script Path: C:\Program Files\Snow Software\Inventory\Agent\ s can-my_powershell.ps1 Steps to Get Data from PowerShell to License Manager. 1) Create a PowerShell script that pulls the information. Example: Simple <Get-Host> command and we are pulling the <InstanceID>. 2) Right the data to a registry entry in PowerShell script.    { Yield-RegistryKey -key HKLM\Snow\Instance -name "InstanceID" -value "$instanceID" -type 1 } 3) Add the below to the snowagent.config file to pull the created   <Registry enabled="true">      <Query>          <Key>...</Key>          <Value>...</Value>       </Query> </Registry>     SnowAgent.config limitations: Registry  ( top ) Optional element.  Only applicable to the Windows Agent.   Include additional information from the Windows Registry in the scan result. <Registry enabled="...">   <Query>...</Query> </Registry> Attributes Attribute Description enabled Acceptable value: true/false Child Elements Element Description Query Represents a registry query. Query  ( top ) Represents a registry query (Windows specific). The query will be used to search for a set of values that will be included as custom registry information in the scan result. <Query>   <Key>...</Key>   <Value>...</Value> </Query> Attributes None. Child Elements Element Description Key Required element.     The sub key (and registry hive) to scan.   Example: HKEY LOCAL MACHINE\SOFTWARE\Microsoft\Windows NT Value Required element.   May be specified multiple times.   Each value represents the name of a value and if found at any location during query will result in that value being included in the scan result. Example: Version Key  ( top ) Required element.     The sub key (and registry hive) to scan.   Example: HKEY LOCAL MACHINE\SOFTWARE\Microsoft\Windows NT <Key recursive="..." /> Attributes Attribute Description recursive Optional element. If used values: true/false   Specifies whether to perform a recursive search starting at the sub key specified. Note that it may take considerable time to perform a recursive scan, if the starting point is a key with many items underneath it. Use recursive queries sparsely. Acceptable value: true/false Child Elements None.        4) Regesty Key is pulled and put in the Snow Inventory database under "Custom\Registy keys"     5) Create a custom field named "InstanceID" where data from Snow Inventory database will be put. 6) Add a SQL Stored Procedure into the SLM SQL database that will pull the data from the Snow Inevntory database registry key " InstanceID" and put it in the customer field InstanceID in LM. (I am looking for a example of this code now) The Stored Procedure is tied to the <Data Update Job>.  During the next DUJ, the registry key will be copied over into the SLM custom field.    7) Custom field is populated in LM under each machine. Another Example Get Local Administrators Example PowerShell to Registry Entry Code: function get-localadministrators {   param ([string]$computername=$env:computername) $computername = $computername.toupper()   $ADMINS = get-wmiobject -computername $computername -query "select * from win32_groupuser where GroupComponent=""Win32_Group.Domain='$computername',Name='administrators'""" | % {$_.partcomponent} foreach ($ADMIN in $ADMINS) {   $admin = $admin.replace("\\$computername\root\cimv2:Win32_UserAccount.Domain=","")   $admin = $admin.replace("\\$computername\root\cimv2:Win32_Group.Domain=","")   $admin = $admin.replace('",Name="',"\")   $admin = $admin.REPLACE("""","")#strips the last " $objOutput = New-Object PSObject -Property @{   Machinename = $computername   Fullname = ($admin)   DomainName =$admin.split("\")[0]   UserName = $admin.split("\")[1]   } $objreport+=@($objoutput)   } return $objreport   } $i = 1 foreach ( $item in ( get-localadministrators ) ) {   if ($i -eq 1) { $locadm = $item.Fullname }   if ($i -gt 1) { $locadm = $($locadm + "," + $item.FullName)}   $i = $i + 1   }   $d = Get-Date   if ($locadm) { Yield-RegistryKey -key HKLM\Snow\LocalAdmins -name "LocAdm" -value "$locadm" -type 1 -lastModified "$d" }
    Expand Post
    • Hi,  thank you for your great answer. Helps me a lot.  I wrote a script like:  $Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi $i = 1 ForEach ($Monitor in $Monitors) { $Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach{[char]$_}) -join "" $Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach{[char]$_}) -join "" $Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach{[char]$_}) -join "" New-Item -Path "HKLM:\Software" -Name TG -EA SilentlyContinue New-Item -Path "HKLM:\Software\TG" -Name Snow -EA SilentlyContinue $regname = "display"+$i+"type" $check = New-ItemProperty -Path "HKLM:\Software\TG\Snow" -Name $regname -Value ($Manufacturer + $Name) -Type String -EA SilentlyContinue if ($check -eq $) { Set-ItemProperty -Path "HKLM:\Software\TG\Snow" -Name $regname -Value ($Manufacturer + $Name) -Type String -EA SilentlyContinue } $regname = "display"+$i+"serial" New-ItemProperty -Path "HKLM:\Software\TG\Snow" -Name $regname -Value $Serial -Type String -EA SilentlyContinue if ($check -eq $) { Set-ItemProperty -Path "HKLM:\Software\TG\Snow" -Name $regname -Value $Serial -Type String -EA SilentlyContinue } $i++ } Script adds or changes registry as I want. At the empty?! config file, I added:  <Registry enabled="true"> <Query> <Key> HKEYLOCALMACHINE\SOFTWARE\TG\Snow </Key> <Value> display1type </Value> <Value> display1serial </Value> <Value> display2type </Value> <Value> display2serial </Value> </Query> </Registry> But the data does not arrive Sno Inventory server.  Why not? Think I didn't understand the correct syntax in the config file.  In which user guide is the powershell script mentioned? 
      Expand Post
      • Community Manager (Flexera Software)

        Hi Jens, I have created a document on how to use the Snow Inventory 5 SMACC tool to create configuation templates.    I also posted the configuation details and thier definitions.   I have reached out to the global pre sales team here at Snow. I will post a working example shortly. 
        • Hi, sry for late reply. Unfortunately your documents didn't help me, cause the first did not describe to change registry and the second documented a wrong example. I write down what worked for me and where I am now struggling. I am using the agent 5.2.3 To get Snow agent reading the correct registry path you cannot use the example in the "All Snow Inventory Agent 5 Settings with Detailed Explanations" document. Here is my example that worked. I marked the data that worked for me as bold. <Registry enabled="true">        <Query>            <Key> HKEY_LOCAL_MACHINE \SOFTWARE\TG</Key>          <Value>Image-Type</Value>  <Value>Image-Version</Value>         </Query>  </Registry> Now agent reads registry and transmits the data to Snow Inventory server. But I cannot get Snow agent to write Registry entries. To test permissions I authorized everyone full rights to this key, but I still get permissions error, when the script runs with Snow agent. If a normal domain user starts the script, it works fine. Is this because of the Script Execution policy? If yes, how can I write reg values with a self written script for Snow agent?  Here is the error output (unfortunately in German): Set-ItemProperty : Der angeforderte Registrierungszugriff ist unzulässig. In Zeile:22 Zeichen:9 +         Set-ItemProperty -Path HKLM:\SOFTWARE\TG -Name $regname -Valu ... +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : PermissionDenied: (HKEY_LOCAL_MACHINE\SOFTWARE\TG:String) [Set-ItemProperty], SecurityException     + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.SetItemPropertyCommand Thank you for your help.
          Expand Post
          • Hi, if the snow agent is executing your powershell script then it can only read and cannot write. If SNOW encrypt the powershell for you then it is executed under a higher privilege and you can write to the registry/file system. however every time you change the script they will need to re-encrypt it for you.... you would need to find another way to execute the powershell script on the computer before the scan which is what I do at the moment
            Expand Post
    • Great post, many thanks. Could you please post some additional info about the SQL stored procedure? Which table in the SnowLicensemanager DB needs to be updated with the data from SnowInventory? UPDATE: Never mind, have figured it out. [SnowLicenseManager].[dbo].[tblCustomFieldValue] needs to be filled with the data from [SnowInventory].[inv].[DataCustomRegKey] CustomFieldID -> depending on your setup [SnowInventory].[inv].[DataCustomRegKey]  ClientID -> [SnowLicenseManager].[dbo].[tblCustomFieldValue]  ElementID  [SnowInventory].[inv].[DataCustomRegKey]  Data  -> [SnowLicenseManager].[dbo].[tblCustomFieldValue]  Value UpdatedDate -> UpdatedBy ->
      Expand Post
      • Yes, you're right. I think you have to connect invetory data and license data by [inv].DataClient.ClientId -> [lic].dbo.tblComputer.ClientID  [SnowInventory].[inv].[DataCustomRegKey]  ClientID  -> [SnowLicenseManager].[dbo].[tblCustomFieldValue]  ElementID  !!!this is not correct!!! You have to take step over ComputerID in [lic].dbo.tblComputer UpdatedDate should be simply the date of DUJ  UpdatedBy you have to Check if it is important whats the content (system user or not) My issue is the StoredProcedure. I'm no SQL-Coder. I am also not sure how to work with SequenceNumber of Inventory.   
        Expand Post
        • Just wrote these two basic queries and did some testing..  /*** UPDATE QUERY - Copies INV.Data to CUSTOMFIELD.Value - 'SystemSKU' is the name of the Custom Field, Remove ClientId for Production ***/ UPDATE CUSTOMFIELD SET CUSTOMFIELD. Value = INV. Data FROM [ SnowLicenseManager] . [ dbo] . [ tblComputer] AS SLM JOIN [ SnowInventory] . [ inv] . [ DataCustomRegKey] AS INV ON SLM. ClientID = INV. ClientID JOIN [ SnowLicenseManager] . [ dbo] . [ tblCustomFieldValue] as CUSTOMFIELD ON CUSTOMFIELD. ElementID = SLM. ComputerID WHERE ModifiedTime = ( SELECT MAX ( ModifiedTime) FROM [ SnowInventory] . [ inv] . [ DataCustomRegKey] WHERE ClientId = '2052' AND Name = 'SystemSKU' ) /*** TEST QUERY to check the results from the UPDATE query - 'SystemSKU' is the name of the Custom Field ***/ SELECT SLM. HostName, SLM. ComputerID, SLM. ClientID, INV. ClientId, INV. RegKey, INV. Name, INV. Data , CVAL. Value , CVAL. UpdatedBy, CVAL. UpdatedDate FROM [ SnowLicenseManager] . [ dbo] . [ tblComputer] AS SLM JOIN [ SnowInventory] . [ inv] . [ DataCustomRegKey] AS INV ON SLM. ClientID = INV. ClientID JOIN [ SnowLicenseManager] . [ dbo] . [ tblCustomFieldValue] as CVAL ON CVAL. ElementID = SLM. ComputerID WHERE ModifiedTime = ( SELECT MAX ( ModifiedTime) FROM [ SnowInventory] . [ inv] . [ DataCustomRegKey] WHERE ClientId = '2052' AND Name = 'SystemSKU' ) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ The Value in the SLM Database is updated correctly, however, in the SLM web console view 'List all Computers' the value is not updated. But - the correct value is shown when I select the client and go to the 'Information' tab or click on 'Edit Computer' and then go to the 'Custom Information' tab.  Weird! Only when I manually change the value in the 'Custom Information' tab, the 'List all Computers' view is updated correctly as well 
          Expand Post
10 of 29

Related  Product Forums


                     → Flexera One



                      → Snow Atlas



                      → FlexNet Manager



                      → Snow License Manager



                       → App Broker


       Need help finding an answer?


        Ask a Question →


Loading
Using Powershell at scan - Example: Scanning Displays