Struggling to understand WMI scripts

xSequentialxxSequentialx Posts: 49Member ■■■□□□□□□□
Ok so i've read through this part of the book a couple of times and its just going completely over my head. Is there any decent sites or videos that explain it better but at a basic level (which i presume is all thats needed for the 70-680.)

Comments

  • azjagazjag Posts: 579Member
    Currently Studying:
    VMware Certified Advanced Professional 5 – Data Center Administration (VCAP5-DCA) (Passed)
    VMware Certified Advanced Professional 5 – Data Center Design (VCAP5-DCD)
  • ClaymooreClaymoore Posts: 1,637Member
    It's more important to focus on what WMI is, why you want to use it and where you need to use it, and not so much on how to write a WMI query. You can use WMI filters (with limits) when applying GPOs, and you can also use WMI to remotely query for information from a PC or group of PCs. There are other uses as well, but those are the most common.

    When it comes to writing the query itself, I use the WMI code creator and copy the query into PowerShell.

    Utility Spotlight: WMI Code Creator
    Download details: WMI Code Creator v1.0

    Here is an example from a GroupWise migration project where the client did not have a software inventory tool. We needed to know if the Outlook deployment to a site was successful, so I used WMI and PoSh.
    #Define Input File
    $ComputerFile = "C:\Scripts\Input\OPSvendor.txt"
    $ComputerList = Get-Content $ComputerFile
    $SoftwareName = "Microsoft Office Professional Edition 2007"
     
    foreach ($NextComputer in $ComputerList)
    {
       write-host "Connecting to $NextComputer..."
    $Installed = get-wmiobject -Query "SELECT * FROM Win32_Product WHERE Name = '$SoftwareName'" -ComputerName $NextComputer
     Write-Host "Installed Variable = $Installed"
     Write-Host "Installed.Name = $Installed.Name"
    if ($Installed.Name -eq $SoftwareName)
    {
     Add-Content "C:\Scripts\Output\Outlook_Installed.txt" "$NextComputer"
     }
    else
    {
     Add-Content "C:\Scripts\Output\Outlook_Not_Installed.txt" "$NextComputer"
     }
    }
    
  • veritas_libertasveritas_libertas CISSP, GIAC x5, CompTIA x5 Greenville, SC USAPosts: 5,735Member ■■■■■■■■■■
    Claymoore wrote: »
    It's more important to focus on what WMI is, why you want to use it and where you need to use it, and not so much on how to write a WMI query. You can use WMI filters (with limits) when applying GPOs, and you can also use WMI to remotely query for information from a PC or group of PCs. There are other uses as well, but those are the most common.

    When it comes to writing the query itself, I use the WMI code creator and copy the query into PowerShell.

    Utility Spotlight: WMI Code Creator
    Download details: WMI Code Creator v1.0

    Here is an example from a GroupWise migration project where the client did not have a software inventory tool. We needed to know if the Outlook deployment to a site was successful, so I used WMI and PoSh.
    #Define Input File
    $ComputerFile = "C:\Scripts\Input\OPSvendor.txt"
    $ComputerList = Get-Content $ComputerFile
    $SoftwareName = "Microsoft Office Professional Edition 2007"
     
    foreach ($NextComputer in $ComputerList)
    {
       write-host "Connecting to $NextComputer..."
    $Installed = get-wmiobject -Query "SELECT * FROM Win32_Product WHERE Name = '$SoftwareName'" -ComputerName $NextComputer
     Write-Host "Installed Variable = $Installed"
     Write-Host "Installed.Name = $Installed.Name"
    if ($Installed.Name -eq $SoftwareName)
    {
     Add-Content "C:\Scripts\Output\Outlook_Installed.txt" "$NextComputer"
     }
    else
    {
     Add-Content "C:\Scripts\Output\Outlook_Not_Installed.txt" "$NextComputer"
     }
    }
    

    +1, when it comes to studying for the 70-680 this is right on.

    If you are planning on being a System Administrator than learning how to do scripting is very important.
    Currently working on: Linux and Python
  • xSequentialxxSequentialx Posts: 49Member ■■■□□□□□□□
    Thanks for the help icon_thumright.gif
Sign In or Register to comment.