nhottinger Posted August 3, 2017 Report post Posted August 3, 2017 I know I can create a collection to search for a specific file, but is there any way to search the data inside a .txt file? Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted August 3, 2017 Report post Posted August 3, 2017 Sounds like the perfect opportunity to use a compliance rule based on a powershell script. You can create result collections on the deployment of compliance rules. Quote Share this post Link to post Share on other sites More sharing options...
nhottinger Posted August 3, 2017 Report post Posted August 3, 2017 Any help getting that setup? Not very familiar with compliance rules. Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted August 3, 2017 Report post Posted August 3, 2017 Sure. First you have to create a configuratione item with a powershell based compliance rule that returns an integer value representing the number of found search patterns. The detection rule script should look like this: (Get-Content -Path "C:\Path\Filename.txt" | Where-Object {$_ -match "your search text"}).count Then you create a new compliance rule based on this configuration item and deploy it to an collection of your choice with a compliance value > 0. Right click the new deployment and create a new compliant collection from the context menu. Quote Share this post Link to post Share on other sites More sharing options...
nhottinger Posted August 3, 2017 Report post Posted August 3, 2017 Thanks Peter. I got it setup but it's not working at the moment. Specifically, I need to search for the .txt file in a specific location, and need the output to be the hostname of the device, and a the data from this file. It is a very small file, 1 short line. Is this possible? Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted August 3, 2017 Report post Posted August 3, 2017 Assuming that by specific location you mean a fixed path, the solution is pretty simple. You can use the environment variable for the computername. (Get-Content -Path "C:\windows\temp\$env:COMPUTERNAME.log" -ErrorAction SilentlyContinue | Where-Object {$_ -match "find me"}).count Quote Share this post Link to post Share on other sites More sharing options...
nhottinger Posted August 3, 2017 Report post Posted August 3, 2017 Correct, the file I need to search is in the same location on every pc (c:\Temp\file.txt). What I'm trying to get out of this, is what the file contains. This file shows us what version number of our image we have on the pc (v 3.2, v 3.3, etc). I need a list of pc names and what version of the desktop image it has, based on the .txt file. Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted August 3, 2017 Report post Posted August 3, 2017 OK, think i got it now. The dynamic file content changes the task at hand. You could still do it by using compliance rules, but it gets quite boring and a lot of work when you have to cover every possible version number. That would require a new rule for every possible version. So let's forget about that. The better approach is to create a new custom WMI class, write the file content to a class property and include this new class in your clients hardware inventory. This way query your SCCM database for the Image Version and create custom reports or collections. Here is a tiny script that creates a new class $file = "C:\temp\file.txt" if(Test-Path -Path "$file" -ErrorAction SilentlyContinue) { # Delete WMI Class if it already exists if(Get-WmiObject OSDImageVersion){Get-WmiObject OSDImageVersion | Remove-WmiObject} # Create new WMI Class OSDImageVersion $ImageVersion = Get-Content -Path "$file" -ErrorAction SilentlyContinue $ImageVersion $wmiclass = New-Object System.Management.ManagementClass("root\cimv2", [String]::Empty, $null); $wmiclass["__CLASS"] = "OSDImageVersion"; $wmiclass.Qualifiers.Add("Static", $true) $wmiclass.Properties.Add("ImageVersion", [System.Management.CimType]::String, $false) $wmiclass.Properties["ImageVersion"].Qualifiers.Add("Key", $true) $wmiclass.Put() # Write WMI Class Property ImageVersion [void](Set-WmiInstance -Path \\.\root\cimv2:OSDImageVersion -Arguments @{ImageVersion=$ImageVersion}) ` } You just need to create a new SCCM Package and run the script on each client once. I would also recommend to get rid of the versioning in the text file during OSD and use WMI from the start. Quote Share this post Link to post Share on other sites More sharing options...
GarthMJ Posted August 4, 2017 Report post Posted August 4, 2017 16 hours ago, nhottinger said: Correct, the file I need to search is in the same location on every pc (c:\Temp\file.txt). What I'm trying to get out of this, is what the file contains. This file shows us what version number of our image we have on the pc (v 3.2, v 3.3, etc). I need a list of pc names and what version of the desktop image it has, based on the .txt file. if you are going to create a PowerShell script to collect, I would take this one step farther and Tattoo the image version in either WMI or registry. This way you can inventory it was Hardware Inventory. I would also make sure that you update your TS to do this as well. Quote Share this post Link to post Share on other sites More sharing options...