I’ve worked with Windows systems for most of my career in technology, and one thing that cannot be understated is the power of Powershell. Powershell is like any other command line tool; give it a command, and it does a thing. This is obviously the expectation, but when you introduce other systems sending commands as well as using their own modules, it can get really confusing when trying to determine what powershell is or isn’t doing.
So, for some context, when Windows discovery is initiated from ServiceNow, it runs a series of PowerShell commands to retrieve various bits of information from the system it’s interrogating. This is done by the MID server importing multiple modules, creating a remote connection to the target machine, setting some variables, and then running the commands to retrieve outputs that will then be used in your discovery patterns. When this works, it’s a beautiful thing.
Debugging a system that has custom modules running commands on remote machines, capturing errors, and spitting them back to you with a wonderfully verbose “Access Denied” error is almost as useful as a screen door on a submarine. Luckily, there are more efficient ways to debug. In this next section, I will walk you through importing the modules required to run those elusive discovery commands directly from your MID server.
The first thing you will need is the ability to log in to your MID server via RDP or your remote desktop application of choice, with admin privileges. Once connected, we can start the module import process.
Open Powershell as an administrator and run(replacing <MIDSERVER> with the name of your MID folder):
Then you can run the following command to see a list of files in your current directory:
At this point, you have a couple of options:
NOTE: You may see a few warnings, but this is expected.
The last thing we need to do is set our remote computer and credentials to be used. You can do that with the following commands:
Now that we have set our credentials and remote computer name/ip we can pass that information into our commands.
At this point, you will be able to run any command that discovery runs during its Identification/Classification/Exploration phase. So, capture the command from your MID log and run it to your heart's content. This should give you a really good indication of where and when discovery is breaking. Below is an example of a command that was captured and troubleshot using this method.
This is the debug log we pulled from the MID (the highlighted portion is the command we will run):
Now we’ve identified the command we can insert our credentials and computer and try locally, which looks something like this:
If the command returns an error, you will be able to determine the module that is being used, the error message, and where the error occurred. Now, continue troubleshooting as you normally would, but this time much faster with more verbosity.
Interested to learn more or need some help troubleshooting? Reach out to us at chat@rapdev.io