Kaseya Community

CMD: How does one exclude certain words in a string for custom field?

This question is answered

Hey guys, I'm trying to create a custom field that will tell me the version of the BIOS on a computer. I've gotten it to function however I have 1 extra stinkin word in there that I don't like.

Ex. BIOS Version: Name OWEJOFEWEO (205.1)

I really want to exclude that "Name" from the results. Anyone have any ideas?

I basically run the command and use the cmd to variable deal in the procedures. Then I slap that variable into my custom field. Nothing too crazy but I would love to learn how to clean that up.

Verified Answer
  • Sorry, you wanted the name:

    (Get-CimInstance -ClassName 'CIM_BIOSElement').Name

All Replies
  • I am not aware of a way to do it in the agent procedure, when I want to do something like this I execute another shell command like this:

    executeshellcommandtovariable("For /f "Delims=: tokens=2" %a in ("#MachineAndPassword#") Do Echo %a",...

    Assuming that value is in #global:cmdresults# you could achieve the same with this:

    executeshellcommandtovariable("For /f "tokens=1,2,3,5*" %a in ("#global:cmdresults#") Do Echo %a %b %c %d %e",...

  • Have your command run powershell to perform the operation and clean up the output as you need. Alternatively you can use the DOS command 'FOR /F' to split output into tokens and select the tokens you want to keep.

    If you share with us what command you are running I can probably give you examples.

  • I studied up on using the For /f command but honestly I don't quite understand how to fully utilize it. I use the command to variable procedure line and in that command I use: wmic bios get name. Then I put the result into my custom field.

  • Wouldn't PowerShell be a lot easier:

    (Get-CimInstance -ClassName 'CIM_BIOSElement').SMBIOSBIOSVersion

  • Sorry, you wanted the name:

    (Get-CimInstance -ClassName 'CIM_BIOSElement').Name

  • Both of those get me the answer that I want. To answer your questions, I don't know, that's why I'm asking in the forums ;p. I'm not too familiar with powershell yet either which i'm definitely trying to learn it. WMIC was the only way I knew how to grab the result I wanted.

    Thank you Jondle, you provided the output I want without the extra hassle of For /F

  • Meh... I found an issue though. I was using CMDTOVARIABLE in the procedures. I'm not sure how to do this to save the output as a variable to pass to system info for the agent. There is no Powershelltovariable command line lol.

  • Figured it out. The Powershell line has the option to create a document to the agent and sent it to #global:psresult#. That's exactly what I needed. Thank you very much everyone.