I wrote this PowerShell script for use as an application detection method inside an SCCM application. The SCCM application would set the network adapter configuration if it is not currently configured properly. This company has a special DNS setup for SCCM clients that is different than for non-SCCM clients. Here is the PowerShell code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#get only network adapters that have a valid IP address $networkConfigStatus = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'" | where { $_.ipaddress -like "192.168.*" } #initial value $valid = "TRUE" #for every valid network adapter found (since some workstations can have dual NIC's) for ($i=0; $i -lt $networkConfigStatus.Length; $i++) { #if each connection has the proper network config then do nothing if ($networkConfigStatus[$i].dnsdomain -like "clients.ad.company.com" -and $networkConfigStatus[$i].FullDNSRegistrationEnabled -like "True" -and $networkConfigStatus[$i].DomainDNSRegistrationEnabled -like "True") { } else { #if the config is wrong then change this to False $valid = "FALSE" } } #if no network adapters are found, report False if ($networkConfigStatus.Length -eq 0) { $valid = "FALSE" } #if the value is still True, then write an output if ($valid -like "TRUE"){ Write-Host "Valid" } |
Of course you would need to change some of these values to make the script work for your organization and its required network settings.
The script only outputs something if the settings are correct. If the settings are wrong, it does not output anything. This is due to how SCCM’s application detection method works with scripts – if there is any output at all from a script, no matter what the output is, then SCCM counts that as the application being detected. If there is no output from the script, SCCM sees the application as undetected.
For an easy way to deploy the correct network settings if this detection method detects invalid settings, check out my DNS Suffix script.
Pingback: How to Set DNS Suffix and Registration using PowerShell | BorisKagan.net
I have a desktop with only one physical network card. The script does not work, because if the variable just get back one network card, it’s not an array.
To solve it change line 2 to:
$networkConfigStatus = @(Get-WmiObject Win32_NetworkAdapterConfiguration -filter “ipenabled = ‘true'” | where { $_.ipaddress -like “192.168.*” })