Powershell Creating WMI ComputerName Case statements

Yashim Greene 1 Reputation point
2021-03-09T02:37:20.96+00:00

I have a bunch of batch scripts that I use to create WMI ComputerName Cases. I want to convert my batch scripts over to powershell scripts but I do not know how to create a ComputerName Lookup case with Powershell. Can I get some assistance with this issue? What I do in my Batch scripts is I create a WMI case that looks at the first 5 letters of the pc name and once it finds a match. I have a goto: for the first 5 letters of the computerName, based on the name it then runs the script associated to that computerName. It works great in my batch script. However, it is time to change to powershell, but I know when to ask for help. I have never created a case in powershell is have no idea what i am doing and could so help.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,928 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mattias Asplund 236 Reputation points
    2021-03-09T04:52:42.213+00:00

    I'm not sure if you want help on Case (switch) statements and/or WMI scripting in Powershell. I'm guessing Case statements, so here is some code adressing that:

    $ComputerName = "ABCDE12345"
    switch ($ComputerName.Substring(0, 5))
    {
        "ABCDE" {
            Write-Host "Found it!"
        }
    }