需要帮助创建一个适用于Windows 7(PowerShell 2.0)和Windows 10(PowerShell 5.0)的PowerShell脚本,以便可以通过GPO推送。 *我们没有域名DHCP我们是从MPLS路由器获得IP租约......
到目前为止,我已经使用Windows 7(非PowerShell)的批处理文件完成了以下操作
Demo using int m_4x4[4][4]
void show(int m_4x4[][4])
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
void clockWiseCout(int m_4x4[][4])
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
Demo using IntVec_t m_16x1
void show(IntVec_t& m_16x1)
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
void clockWiseCout(IntVec_t& m_16x1)
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
FINI 364 us
此代码适用于Windows 10(PowerShell 5.0)
@ECHO OFF
set vardns1=1.1.1.1
set vardns2=2.2.2.2
ECHO Setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%
ECHO Setting Secondary DNS
netsh int ip add dns name = "Local Area Connection" addr = %vardns2%
ECHO Flushing DNS
ipconfig /flushdns
ECHO Registering New DNS settings
ipconfig /registerdns
答案 0 :(得分:0)
构建两个脚本并在GPO上使用WMI过滤在W10上运行一个,在W7系统上运行另一个。比试图制作多态脚本更容易。
答案 1 :(得分:0)
为什么不能在Windows 7计算机上运行Windows 10 PowerShell脚本?
您使用WMI设置DNS地址应该没有问题。
您可以尝试在Windows 7计算机上本地运行它并分享错误吗?
如果您通过GPO使用PowerShell,那么将错误写入日志文件会很不错。
即使是脚本末尾的基本内容
if($Error)
{
Export-Clixml -Path C:\GPOError.xml
}
这将保存整个错误对象 您可以将其导入PowerShell并使用
进行查看导入-CLIXML