备份 DNS 服务器

发布于 2024-08-16 09:56:47 字数 394 浏览 0 评论 0原文

我在这里的脚本有问题,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冧九 2024-08-23 09:56:47

为了使该批处理正确运行,请确保启用延迟扩展。只需在批处理文件的开头添加 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.

灰色世界里的红玫瑰 2024-08-23 09:56:47

查看 PowerShell 它比旧的批处理文件灵活得多做事的方式。

Look into PowerShell It is a lot more flexible than the old batch file way of doing things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文