Jump to content


nhottinger

Collection to search for specific data in .txt file

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.