Solved

powershell script to look for DNS suffix for this connection

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

20 Experts available now in Live!

Get 1:1 Help Now