Solved

powershell script to look for DNS suffix for this connection

Posted on 2012-04-04
4
1,892 Views
Last Modified: 2012-05-08
Hi All,

I need a powershell script to read in a text file that contains computer name and look for DNS suffix for this connection, then print out the computer name and the DNS suffix for this connection.


Please help!
0
Comment
Question by:fireburn11
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
X_layer earned 500 total points
ID: 37808580
Lets say that you have computers listed in computers.txt file. Then you can try something like this:
Get-Content .\computers.txt | Foreach-Object {Get-Wmiobject Win32_NetworkAdapterConfiguration -ComputerName $_ -Property * -Filter "DNSHostName = '$_'" | select DNSHostName,Description,DNSDomainSuffixSearchOrder}

Open in new window

0
 

Author Comment

by:fireburn11
ID: 37812193
I am getting access denied error when executing the script.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 37821152
To retrieve the original info of each computer, you need a single, valid user for all computers, and run the script under that account. Or provide a PSCredential object with each WMI command, like
$creds = New-Object System.Management.Automation.PSCredential ("MyUser", 
    (ConvertTo-SecureString -AsPlainText -Force "MyPwd") )
gc .\computers.txt | % {
  Get-Wmiobject Win32_NetworkAdapterConfiguration -ComputerName $_ -PsCredentials $creds -Property * -Filter "DNSHostName = '$_'" |
  select DNSHostName, Description, DNSDomainSuffixSearchOrder
}

Open in new window

(if you want to use a single account different from your one the script is running in).
Usually you will provide a domain or local admin account for that purpose.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 37889622
How did you solve the "access denied" issue?
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question