Solved

powershell script to look for DNS suffix for this connection

Posted on 2012-04-04
4
1,825 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 68

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 68

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now