Do you need to examine two textual content strings in PowerShell however couldn’t discover a Cmdlet to do that? I had the identical downside, so I developed a PowerShell script (a operate, Examine-TextStrings).
Overview
I used to be writing the article PowerShell IF ELSE Defined once I got here throughout a query about evaluating two textual content strings with PowerShell. To be particular, I need to examine two textual content strings like those beneath:
"My title is Victor" "My title just isn't Tammy"
I would like to have the ability to checklist the strings which can be related in each textual content strings. Equally, I need to checklist the textual content strings which can be completely different in each textual content strings.
Firstly, I attempted the Examine-Object cmdlet however as anticipated, it is not going to do the job. I performed round with logical operators however none of them would do the job.
#1 Greatest Total
Sale
Below Desk Cable Administration Tray No Drill, Metallic Mesh Cable Administration Below Desk with Clamp Mount, 2 Gap Cable Tray with Wire Administration and Twine Organizer for Dwelling Workplace Standing Desk
- 【No Drill Mounted】Cable administration tray might be assembled in as little as 3 minutes or less-simply. Aspect clips simply clampe the sting of desk, cross by way of the holes on the edges, and safe extra cables with baskets. Desk cable administration helps inward or outward set up to satisfy your wants in numerous eventualities, and gives you with nice comfort when accumulating and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer beneath desk built-in mushy rubber pads on the clamp defend your desk from scratches, so you’ll not injury your furnishings or workplace.
- 【Sturdy and Stunning】Twine administration beneath desk is manufactured from high-quality carbon metal and holds about 15 lbs. The wire basket has 2 holes on either side of the tray to allow your cables to cross freely. Cable baskets are appropriate for desk thickness use from 0.4″ to 2″.
- 【House Saving & Maintain Organized】Desk cable administration tray holds all of your energy cords, outlet strips, USB hubs and pc transformers hidden out of your ft, and the information cables is not going to enter the vacuum cleaner to maintain your desk clear and tidy. Desk wire organizer can be appropriate to be used within the kitchen and outdoor.
- 【Cut back Security Dangers】Cable tray beneath desk retains all plugs away out of your children, no extra fear about tripping. Utilizing 2 holes wire tray saves further house, helps you simply cabling and wire safety. The mesh design just isn’t straightforward to build up mud, however avoids security accidents attributable to messy wires.
Lastly, I made a decision to create a customized operate that can examine two textual content strings. I referred to as the operate Examine-TextStrings.
Syntaxes

The Examine-TextStrings operate has two syntaxes. Right here they’re…
Examine-TextStrings [-FirstTextString] <String[]> [-SecondTextString] <String> [[-DisplaySimilar]] [[-DisplayDifference]] [<CommonParameters>]
Examine-TextStrings [-FirstTextString] <String[]> [-SecondTextString] <String> [[-DisplaySimilar]] [[-DisplayDifference]] [[-OutFile]] [[-Path] <String>] [<CommonParameters>]
You employ the primary syntax to show the results of the command on the PowerShell console. Quite the opposite, you should utilize the second syntax to ship the output of the command to a textual content file.
To be taught extra, learn the subsequent part…
Parameters

To successfully use the PowerShell operate, Examine-TextStrings to match two textual content strings, you want to perceive the parameters of the operate.
Within the desk beneath, I’ve defined all of the parameters and the best way to use them.
| Parameters of Examine-TextStrings | Feedback/Notes |
|---|---|
| FirstTextString | This parameter is used to specify the primary textual content string you need to examine. It’s a required parameter |
| SecondTextString | Use the SecondTextString to specify the second textual content string you need to examine in PowerShell. Just like the FirstTextString parameter, SecondTextString is a required parameter |
| DisplaySimilar | The DisplaySimilar parameter is a Change parameter. It signifies that it doesn’t require any enter. You simply have to specify the parameter. So, once you specify the DisplaySimilar parameter, Examine-TextStrings shows the components of each texts which can be related or the identical. |
| DisplayDifference | That is additionally a Change parameter. If you happen to specify the DisplayDifference parameter, Examine-TextStrings shows the texts which can be completely different within the texts strings you’re evaluating |
| OutFile | You should utilize this parameter to ship the output of Examine-TextStrings to a textual content file. The OutFile parameter is a Change; so it doesn’t require enter. The parameter is optionally available |
| Path | Use the Path parameter to specify the trail to avoid wasting the textual content file. If the OutFile parameter is specified however the Path parameter just isn’t specified, Examine-TextStrings will save the textual content file within the consumer’s temp folder, normally situated in [Windows Install Drive]CustomersAppDataLocalTempCompareString. In any case, the title of the textfile is within the format dd-MM-yyyy.txt
Alternatively, in the event you specify a path with the Path parameter, Examine-TextStrings will save the textfile in $Path + “CompareString” |
Examples

Now that you recognize the syntaxes and parameters of Examine-TextStrings, it’s time to see some examples.
Rank #2
Sale
WOLFBOX MegaFlow 50 Compressed Air Duster-110000RPM Tremendous Energy Electrical Air Duster, 3-Gear Adjustable Mini Blower with Quick Charging, Mud Blower for Pc, Keyboard, Home, Out of doors and Automotive
- Highly effective Turbo Fan:WOLFBOX MegaFlow 50 electrical air duster reaches speeds of as much as 110,000 RPM, successfully eradicating mud and particles. It options three adjustable velocity settings to swimsuit completely different cleansing duties.
- Economical and Reusable: Constructed from sturdy supplies with a long-lasting battery, the WOLFBOX MegaFlow 50 is a sustainable various to disposable air cans, enhancing your cleansing expertise.
- Moveable and Light-weight: Weighing solely 0.45 lb, this compact air duster is simple to hold. The included lanyard ensures handy use each indoors and outdoor.
- Large Utility: WOLFBOX MegaFlow 50 electrical air duster comes with 4 nozzles, making it appropriate for a wide range of scenes, similar to computer, keyboards, or different digital gadgets. It additionally serves nicely for residence clear and automobile duster.
- 3.5 Hours Quick Charging: WOLFBOX MegaFlow 50 electrical air duster recharges in simply 3.5 hours with a type-C cable. Take pleasure in as much as 240 minutes of use on the bottom setting, with 4 charging choices to fit your wants.To make sure optimum efficiency of your MF50, please totally cost the battery earlier than use.
Earlier than then although, I’ll present you the best way to obtain and set up the operate.
1. Obtain and Set up
Comply with the steps beneath to obtain and set up the Examine-TextStrings operate:
- Click on the Obtain Examine-TextStrings hyperlink. Then, save the zip file to a folder
- Subsequent, unzip the file and reserve it in:
C:Program FilesWindowsPowerShellModules
To make sure you get the suitable path, enter the command beneath in PowerShell and press enter.
$env:ProgramFiles + "WindowsPowerShellModules"
If this path doesn’t exist, it’s essential to create the total one. To create the trail, you may open PowerShell as administrator and run the next instructions:
$ModulesFolder = $env:ProgramFiles + "WindowsPowerShellModules" New-Merchandise -Path $ModulesFolder -ItemType Listing -Power | Out-Null
When you create the trail, copy the unzipped folder, Examine-TextStrings to the final folder within the path…
To present you a visible presentation of what the trail seems like, see the screenshot beneath.
Rank #3
Compressed Air Duster,130000RPM Tremendous Energy Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Mini Blower with LED Gentle,Mud Remover for Pc/Home/Out of doors/Automotive
- Highly effective Turbo Fan:CAGIWIRU Electrical Air Duster have reached velocity as much as 130000RPM,Can environment friendly take away mud and particles.With LED gentle and Three Adjustable Velocity to satisfy with completely different cleansing duties.
- With Connected USB C Fasting Charging cable.Charing 3 hours,Take pleasure in as much as 240 minutes of use on the bottom setting, For third velocity can use for 25mins.with 4 charging choices to satisfy together with your wants.
- Large Utility:Upgraded connected 5 completely different nozzles,making it appropriate for a wide range of scenes, similar to automobile,pet, computer, keyboards, and different digital gadgets. It additionally serves for workplace and residential clear duster.
- Useful Design & Moveable:Cordless air duster electrical nozzle is Gentle weight and small dimension, design and comfy to carry and house saving, handy to hold round. You may put it in your room or contained in the automobile with out taking over house.
- Guarantee & Assist: Our Electrical air duster comes with 5 years guarantee and 24/7 customer support. Throughout this era, when you’ve got any questions,pls kindly be at liberty to contact us.

- After getting copied the folder to the Modules folder, open PowerShell as administrator and run the next instructions
Import-Module Examine-TextStrings -Power
Whenever you run the command, you’ll be prompted to verify that you simply need to set up the module. Sort R and press enter key.

Now that you’ve got downloaded and put in Examine-TextStrings, proceed to the subsequent sub-sections to see the best way to use the PowerShell operate to match two textual content strings.
Earlier than then, although, you may run the command beneath to show all of the examples…
Get-Assist Examine-TextStrings -Examples
The command shows all of the examples I focus on within the subsequent sub-sections. Nonetheless, for particulars, see the sub-sections beneath this screenshot.

2. Show the Similarity Between Two Textual content Strings
On this instance, I need to show the similarity between the 2 textual content strings, “My title is Victor” and “My title is Ashiedu”. Right here is the command…
Examine-TextStrings -FirstTextString "My title is Victor" -SecondTextString "My title is Ashiedu" -DisplaySimilar
Right here is the lead to PowerShell…

3. Show the Distinction Between Two Textual content Strings
Within the final instance, I in contrast two textual content strings and displayed the distinction between the textual content strings. On this instance, I need to show the distinction between two textual content strings.
Particularly, I need to show the distinction between two textual content strings, “My title is Victor” and “My title is Ashiedu”. Right here is the command…
Examine-TextStrings -FirstTextString "My title is Victor" -SecondTextString "My title is Ashiedu" -DisplayDifference
The distinction between this final command and the earlier one are the parameters, DisplaySimilar and DisplayDifference.

4. Show the Similarity and the Distinction Between Two Textual content Strings
This instance combines the final two examples. This time, I need to show the similarities and variations between two textual content strings.
Just like the opposite examples, my two textual content strings are: “My title is Victor” and “My title is Ashiedu”. Right here is the command:
Examine-TextStrings -FirstTextString "My title is Victor" -SecondTextString "My title is Ashiedu" -DisplaySimilar -DisplayDifference

5. Ship the Similarity and the Distinction Between Two Textual content Strings to a Textual content with No Path Parameter
If you happen to moderately ship the output of the Examine-TextStrings operate to a textual content file, specify the OutFile parameter. Optionally, you may specify the Path parameter.
If you don’t specify the Path parameter, the operate will save the file in your Temp folder. See the parameters part of this information for extra particulars.
Greatest Worth
Sale
Vaydeer Wrist Relaxation for Keyboard and Mouse, Pc Ergonomic Wrist Assist Pad, Smooth Reminiscence Foam Arm Cushion for Desk, Palm Hand Workplace Laptop computer Typing
- 【Softer and Extra Comfy】Vaydeer wrist relaxation has distinctive diamond sample, which is the mix of softness and aesthetics. The supplies of wrist relaxation are improved into increased high quality reminiscence foam and lined with silky easy lycra. The pc wrist relaxation makes you as comfy and cushiony as like relaxation your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist help. Primarily based on ergonomic design, the distinctive concave form is the proper match in your wrist joints. The wrist relaxation pad suits most pc keyboards and laptops, enhance hand and wrist posture, launch your wrist and arm stress.
- 【Non-Slip Rubber Backside】That includes an anti-skid silicone base on the underside, this wrist keyboard help stays firmly in place in your desk, stopping the padding from sliding round, guaranteeing steady and constant wrist help throughout prolonged pc periods.
- 【Higher Expertise & Ache Reduction】Our keyboard arm relaxation is helpful to alleviate the soreness attributable to direct contact and friction between your arm and a tough desk floor, lowering the chance of wrist fatigue or carpal tunnel. The mushy texture of reminiscence foam can evenly distribute the stress round your wrists and supply good help with simply sufficient give.
- 【Useful in A number of Situations】Whether or not you are working, learning, writing, typing, gaming, this keyboard and mouse relaxation combo is a necessary accent so as to add consolation and help to your palms and wrists. It’s additionally an excellent reward for males, girls, household, buddy, coworker, gamer, instructor, and many others.
Right here is the command…
Examine-TextStrings -FirstTextString "My title is Victor" -SecondTextString "My title just isn't Bunmi" -DisplaySimilar -DisplayDifference -OutFile
The command doesn’t return any outcome on the PowerShell console. Relatively, it creates a textual content file. Here’s a screenshot of the textual content file…

6. Ship the Similarity and the Distinction Between Two Textual content Strings to a Textual content File with the Path Parameter
Within the final instance, I didn’t specify the Path parameter. So, the operate saved the textual content file report in $env:TEMPCompareString.
Nonetheless, if you need the operate to avoid wasting the textual content file in a location you specify, use the Path parameter. Right here is an instance command:
Examine-TextStrings -FirstTextString "My title is Victor" -SecondTextString "My title just isn't Bunmi" -DisplaySimilar -DisplayDifference -OutFile -Path D:G-Drive-P
The command saves the textual content file in D:G-Drive-P.

Conclusion
Similar to you, I needed to match two textual content strings with PowerShell however I couldn’t discover a Cmdlet. So, I created a operate referred to as Examine-TextStrings.
You should utilize this operate to match any two textual content strings. The operate can both show the outcome within the console or ship it to a textual content file.
Along with that, you may show the similarity between the textual content strings. Alternatively, you may show the distinction between the 2 textual content strings.
I hope you discovered this practice operate helpful. I additionally hope that I used to be in a position to clarify how the operate works.
In that case, click on on “Sure” beside the “Was this web page useful” query beneath. You may additionally categorical your ideas and opinions through the use of the “Depart a Remark” kind on the backside of this web page.
Lastly, to obtain extra free PowerShell scripts and features, go to our PowerShell Script Repository web page.
Product costs and availability are correct as of the date/time indicated and are topic to vary. Any worth and availability data displayed on Amazon on the time of buy will apply.





