PowerShell DNS query

Steve Bona
Steve Bona used Ask the Experts™
on
With my little powershell command i try to get CNAME record from domain.
When i execute this command <Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001> i have all information. But when it comes to filter to have specific result there is no information for this command <Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001 | Where {$_.RecordData -like "S-SUBCA001*"}>
In the attached file I put the screenshot of the results of the console powershell
CNameOutPut.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AlexSenior Infrastructure Analyst

Commented:
Where {($_.RecordData -like "S-SUBCA001*")}
AlexSenior Infrastructure Analyst

Commented:
Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001 | Where {$_.RecordData -like "S-SUBCA001*"} | select-object HostName, RecordType, Type, timestamp,TimeToLive, RecordData   

Open in new window



That's another way, it could be related to the fact you don't have a select-object in there for your output.
Steve BonaInformation Technology Specialist

Author

Commented:
Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001 | Where {$_.RecordData -like "S-SUBCA001*"} | select-object HostName, RecordType, Type, timestamp,TimeToLive, RecordData  
It doesn't work ...

If you see in my file this command Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001 | Where {$_.HostName -eq "pagesblanches"} works fine but i need to filter from RecordData..
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
RecordData is an object itself; try it like this:
Get-DnsServerResourceRecord -ZoneName "ccsmtl.lab" -RRType CName -ComputerName S-ADS001 | Where-Object {$_.RecordData.HostNameAlias -like "S-SUBCA001*"}

Open in new window

Steve BonaInformation Technology Specialist

Author

Commented:
It works well, and thanks for the explanation why the previous command did not work before.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial