备份 DNS 服务器
我在这里的脚本有问题,
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a
If /i "%dhcp%" == "Yes" (
REM do command here
) Else (
REM script to backup DNS servers to environment variables
)
我尝试了多种方法,使用第一个 for /f 示例来尝试将 DNS 服务器条目放入环境变量中以便稍后使用。
因此,基本上,如果禁用 DHCP,我正在寻找一种将 dns 服务器备份到环境变量(主/辅助 DNS)的方法。
I have a problem with this script here
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a
If /i "%dhcp%" == "Yes" (
REM do command here
) Else (
REM script to backup DNS servers to environment variables
)
I've tried numerous ways using the first for /f example to try and get the DNS Server entries into environmental variables to be used later.
So basically I'm looking for a way to backup the dns server/s to environment variable/s (primary/secondary DNS) if DHCP is disabled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使该批处理正确运行,请确保启用延迟扩展。只需在批处理文件的开头添加
setlocal ENABLEDELAYEDEXPANSION
即可。但它不会“将 DNS 服务器条目获取到环境变量中”,我认为这是一个不同的问题。
For this batch to properly run, make sure you enable delayed expansion. Just add
setlocal ENABLEDELAYEDEXPANSION
at the beginning of your batch file.But it will not "get the DNS Server entries into environment variables", which I believe is a different question.
查看 PowerShell 它比旧的批处理文件灵活得多做事的方式。
Look into PowerShell It is a lot more flexible than the old batch file way of doing things.