- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to read the windows host file using PowerShell?
Windows Host file that maps the hostname and the IP address is the plain text file. So reading the host file is simpler. We just need to use the Get-Content command to retrieve the file content.
Generally, the host file is stored at the location c:\windows\System32\drivers\etc\. If the OS is installed at that location.
Or you can use $env:Windir to get the windows directory.
To get the file content,
Example
Get-Content $env:windir\system32\drivers\etc\hosts
Output
# Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost
To get the host file from the remote server,
Get-Content \Computer1\c$\windows\system32\drivers\etc\hosts
- Related Articles
- How to update the windows host file entry using PowerShell?
- How to add the entry in the windows host file using PowerShell?
- How to read the XML file in PowerShell?
- How to delete the windows certificate using PowerShell?
- How to Get Windows features using PowerShell?
- How to remove windows features using PowerShell?
- How to host a web-service using IIS (windows) and .net
- How to get the Windows certificate details using PowerShell?
- How to get the windows performance counter using PowerShell?
- How to get the windows authentication settings using PowerShell?
- How to stop a windows service using PowerShell?
- How to start a windows service using PowerShell?
- How to start multiple windows services using PowerShell?
- How to share a windows folder using PowerShell?
- How to remove windows folder sharing using PowerShell?

Advertisements