Sign in to follow this  
Followers 0
JustinM

[HELP] Compare String to String

3 posts in this topic

Hello all,

I need help on how to compare one string to another. For this example, I would like to compare the CPU installed in my system with the CPU listed in a text file.

In my text file, which will be $wso, will contain the following string:

"CPU-4770K" --- txt file location = C:\Test.txt. This line can be anywhere in the text file.

Now, my system has a 4770K installed and I get that information using powershell:

$(Get-CimInstance win32_processor).Name, which gives me the output: "Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz" -- This will be outputted to a file located C:\test2.txt

For a human, this is easy to tell that those two strings are the same product. How can I write a simple script to be like "this system has an intel 4770k installed, and the text.txt file contains the words "4770K", so this is true.

I hope I worded this to make sense.

Share this post


Link to post
Share on other sites



I'd format your text file better and at least make it i7-4770k

Global $wso = "i7-4770k"

If (CompareCpu($wso, CpuName())) Then
    MsgBox("", "", "They're the same!")
Else
    MsgBox("", "", "They're not the same :(")
EndIf

Func CompareCpu(Const $sCompareAgainst, Const $sValue)
    Local $sRegexp = StringRegExpReplace($sValue, " CPU .*", "")
    Local $sCleanedString = StringTrimLeft($sRegexp, StringInStr($sRegexp, " ", 0, -1))
    ConsoleWrite("Processor = " & $sCleanedString & @LF)
    Return ($sCompareAgainst = $sCleanedString)
EndFunc   ;==>CompareCpu

Func CpuName()
    Return RegRead ("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0","ProcessorNameString")
EndFunc   ;==>_CpuInfo

 

Share this post


Link to post
Share on other sites

the $wso contents get pulled from an SQL database :o

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0