Showing posts with label wmi. Show all posts
Showing posts with label wmi. Show all posts

Friday, May 15, 2015

LSPCI using WMI ( WMIC )


From Command Prompt:
Wmic path win32_pnpentity where "deviceid like '%PCI%'" get name,deviceid

with powershell:
gwmi win32_pnpentity | where{$_.deviceid -match "PCI"} | select name,deviceid

Monday, September 9, 2013

Update DNS Server setting on Multiple Servers with powershell

Had to update the DNS server settings on a few servers (80+).
Because I had a mix 23/28/28r2/12 servers decided wmi was the path forward + powershell.
  • issues with when doing contains, until I performed a convert to string [String]


  • Stumped by the String setting for a little while was trying .tostring()

  • Script in 3 parts:
    1. check all the servers to see if hard code to old DC
    2. Update the DHCP server options on all authorised DHCP servers
    3. Purge any scope with setting for old DC to use the server option

    Btw: some servers dont reply correctly to WMI so... prepared to check manually (and maybe fix wmi)

    #StartHere :)
    $OUName= 'OU=Servers,DC=KoolKids'
    $TheComputers = Get-ADComputer -filter * -searchbase $OUName
    $results = @()
    
    Foreach ($server in $TheComputers) {
    if(Test-Connection $server.name -Count 1 -quiet){
                $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $server.name| where{$_.IPEnabled -eq “TRUE”} 
                    Foreach($NIC in $NICs) {
                    $FTW=$NIC.DNSServerSearchOrder
                    $FTW =[String]$FTW
                   # write-host $FTW
                    If ($FTW.contains("10.10.3.1")) {
                                           $results += New-Object PSObject -Property @{
                                           Server = $server.name
                                           DNS = $FTW
                                              }
                                #update the DNS Server for this NIC
                                $DNSServers = "172.18.0.10","172.18.0.11"
                                $NIC.SetDNSServerSearchOrder($DNSServers)
                        }
                    }
            }
        }
    #set the default server scope options to correct setting
     foreach ($dhcpserver in Get-DhcpServerInDC){
     if(Test-Connection $dhcpserver.DNSName  -Count 1 -Quiet){
                #Remarked out so that all active DHCP servers get updated!
                #If ($FTW.contains("10.10.3.1")) { 
                 $FixScope=[System.Net.Dns]::GetHostAddresses($dhcpserver.DNSName).IPAddressToString, "172.18.0.10", "172.18.0.11"
                 Set-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -Value $FixScope
                #}
            }
     }
    
     #clear out the scope options
     # WARNING SERVER OPTIONS MUST HAVE a SETTING OR BAD THINGS HAPPEN
      foreach ($dhcpserver in Get-DhcpServerInDC){
                 foreach ($TheScope in (Get-dhcpserverv4scope -computername $dhcpserver.DnsName)){
                         $target=$null
                         $Target=Get-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -ScopeId $TheScope.ScopeId -ErrorAction SilentlyContinue
                         $Target=[String]$target.Value
                          If ($Target.contains("10.10.3.1")) {
                          Remove-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -ScopeId $TheScope.ScopeId 
                          }
            }
     }
    
    

    Friday, July 8, 2011

    wmic “Invalid XSL format (or) file name.”

    So on my windows 7 box trying to:
    wmic product get /format:csv
    produces a output:
    Invalid XSL format (or) file name.

    Located teh csv.xsl file in C:\windows\system32\wbem\en-US
    Guessed that it was unable to locate the xsl format file...
    so copied it to the local path and it worked !
    Confirmed this with Process monitor :-(

    It seems to be looking for the correct locale so I added a C:\windows\system32\wbem\en-US to C:\windows\system32\wbem\en-AU

    since we all don't live in the US of A... :-|

    Alternative options are:
    I just copied to C:\windows\system32\wbem\en-US\*.xls to C:\windows\system32