One common task in troubleshooting is comparing two entities. These can be environments, servers, files, or other objects. There's a myriad of tools we can use, but one built-in tool to Windows platforms is PowerShell and it comes with a useful compare function. In the video, PowerShell: Compare-Object Function, we look at using this built-in function by comparing two files - a task we often do when comparing two configuration files of environments where functionality works in one, but not the other.
In the video, we look at solving the possible issues with this built-in function:
- Understanding the SideIndicator and what this means when we look at two objects - in this case files, but keep in mind that we may be looking at two environment variables, etc.
- How to filter for only looking at the differences between the objects. In many cases with troubleshooting, we only want to return what's different because what's equal doesn't matter. When looking for differences, we see that PowerShell makes this the default option when using this built-in function.
- How to include what's equal along with what differs - in this case, with the files. In fewer cases, we may want to know what's different and what's the same.
- A quick note about how we may want to filter further, relative to the output, such as ordering the output.
While we can find many helpful tools to compare files or other objects, PowerShell comes with this operation built-in, so provided you can read the output, you'll already have a tool at your disposal to use.