如何在使用 PowerShell 時向 Windows 主機檔案新增條目?
如需將內容新增到主機檔案,我們首先需要使用Get-Content 命令檢索內容,然後需要在新增條目後將內容設定為主機檔案。如下所示。我們需要向其新增全域性條目。
示例
$file = "C:\Windows\System32\drivers\etc\hosts" $hostfile = Get-Content $file $hostfile += "8.8.8.8 Google.com" Set-Content -Path $file -Value $hostfile -Force
一旦檢查主機檔案條目 "8.8.8.8 Google.com"將新增到主機檔案。
如需在遠端計算機上新增條目,您只需要將該檔案位置指向遠端伺服器的主機檔案,其餘內容將保持不變。
示例
$file = \Comptuter1\C$\Windows\System32\drivers\etc\hosts $hostfile = Get-Content $file $hostfile += "8.8.8.8 Google.com" Set-Content -Path $file -Value $hostfile -Force
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP