Help with the script. Working on some servers but not the others

I found this script to uncheck DNS registration on TCP/IP settings for all our servers - 2008, 2012 but it doesn't work on some servers. Here is the error that I am getting. Please help.
thank you!

(Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=True").GetRelated('Win32_NetworkAdapterConfiguration') | ForEach-Object {$_.SetDynamicDNSRegistration($false,$false) }

+ (Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=True").GetRelated <<<< ('Win32_NetworkAdapterConfigura
tion') | ForEach-Object {$_.SetDynamicDNSRegistration($false,$false) }
    + CategoryInfo          : InvalidOperation: (GetRelated:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Maybe you can suggest a better script that will work with all the servers. thank you!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phil DavidsonCommented:
I would try this:

Open in new window

(Code taken from this link.)

If that doesn't work, what is the version of PowerShell that the script doesn't work on?

Use this command to find out:

Open in new window

creative555Author Commented:
THank you so much! Where would you put this command though?


Could you please re-post the entire revised script?
creative555Author Commented:
I tried to run this script but it fails with the error that im missing closing }. I tried to fix it but failed.
Please help. I just need to get that option unchecked on all the servers -TCP/IP Settings option for DNS -“Register this connection’s addresses in DNS”

function CheckRemoteNetworkInterfaceIP {
Param ( [parameter(mandatory=$true)][string]$arg1,

$nics = gwmi Win32_NetworkAdapter -Computername $arg1 -Filter "NetConnectionID = '$NetConnectionID'"
#$nics = gwmi Win32_NetworkAdapter -Computername $arg1 -Filter "NetConnectionID = 'Service'"
$nics | {
    $Script:IPAddress = @($_.GetRelated('Win32_NetworkAdapterConfiguration'))[0].IPAddress[0]
Check Out How Miercom Evaluates Wi-Fi Security!

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom on how WatchGuard's Wi-Fi security stacks up against the competition plus a LIVE demo!

Phil DavidsonCommented:
Do you notice what is different about the servers that your command works on compared the servers that your command fails on?

Can you try this?
Get-NetIPConfiguration |
Get-NetConnectionProfile |
Where IPv4Connectivity -ne "NoTraffic" |
Set-DnsClient -RegisterThisConnectionsAddress:$false -Verbose

Open in new window

Above taken from this link.
creative555Author Commented:
I found this script below that is working on all servers remotely.

$Computers = Get-Content "e:\scripts\computers.txt"

    ForEach ($Comp in $Computers)

            $DNSCheck = Get-WmiObject -Class Win32_NetWorkAdapterConfiguration -ComputerName $Comp | ? { $_.IPAddress -ne $null }

                If ($DNSCheck.FullDNSRegistrationEnabled -eq $false)

                    Write-Warning "$Comp DNS setting is already unchecked"







Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
Found a different script that resolves the issue. Thank you so much for your help. The posted one was throwing the errors that I couldn't resolved. Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.