Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Search file for specific text and if found write a number into a variable

$
0
0

I know that this is probably really easy but I am drawing a blank on how to accomplish it.  Here is what I have:

$dir = "\\BHC\D$\PDX\Logs\Threshold Manager_*_*.log"

$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name
$Content = Get-Content -Path $latest | Where {$_.Contains("
\\BHC\Server\Bytes Total/sec")}

Basically if the file contains the text "\\BHC\Server\Bytes Total/sec" I want to output the number "540" to a variable so that I can use it to reference content in a SQL database.  I know how to reference the DB already...

Thanks in advance for your help!

 

 

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles