英文:
Adding WSUS Computers with similar names to different TargetGroups
问题
我基本上只是过滤带有“wik”或“xwik”名称的计算机,如下所示:
假设我们有以下服务器:
testwik.com 和
testxwik.com
Get-WsusServer | Get-WsusComputer -NameIncludes "wik" -ComputerTargetGroups "Unassigned Computers" | Add-WsusComputer -TargetGroupName "Friday_Patch"
Get-WsusServer | Get-WsusComputer -NameIncludes "xwik" -ComputerTargetGroups "Unassigned Computers" | Add-WsusComputer -TargetGroupName "DMZ_Patch"
问题是,每台计算机的名称中都含有“xwik”,显然也都含有“wik”,在运行脚本后,所有“xwik”计算机都会错误地放入“Friday_Patch”目标组中,而不会放入“DMZ_Patch”目标组中,即使它是在第一个提示之后运行的,因为它不再是“Unassigned Computers”的一部分。 有没有人有解决这个问题的想法?
根据我理解的 -NameInCludes 参数的作用类似于通配符,所以 "wik" 基本上是 "wik" 等等,但我还没有找到排除它的方法?也许可以使用 if-语句?但我无法正确地解决它,所以我感谢您的帮助!
英文:
I am basically just filtering for computers with "wik" or "xwik" in their name like the following:
Lets assume we have the servers:
testwik.com and
testxwik.com
Get-WsusServer | Get-WsusComputer -NameIncludes "wik" -ComputerTargetGroups "Unassigned Computers" | Add-WsusComputer -TargetGroupName "Friday_Patch"
Get-WsusServer | Get-WsusComputer -NameIncludes "xwik" -ComputerTargetGroups "Unassigned Computers" | Add-WsusComputer -TargetGroupName "DMZ_Patch"
Problem is, every Computer that has xwik in it's name obviously also has wik in it's name and after running the script all xwik computers would falsely be put into the "Friday_Patch" Target-Group and wouldn't be put in "DMZ_Patch" even tho its ran after the first prompt because it's not part of "Unassigned Computers" anymore. Does any one have an idea to solve this issue?
The -NameInCludes Parameter, to my understanding, acts like a wildcard, so "wik" is basically "* wik *" etc. but i have not found a way to exclude it?
Maybe an if-Statement? But i cant figure it out properly, so I appreciate your help!
答案1
得分: 0
使用简单的if
语句来执行以下操作之一:
Get-WsusServer | Get-WsusComputer -NameIncludes "wik" -ComputerTargetGroups "Unassigned Computers" | ForEach-Object {
if ($_.Computer -like '*xwik*'){
$_ | Add-WsusComputer -TargetGroupName "DMZ_Patch"
}
else {
$_ | Add-WsusComputer -TargetGroupName "Friday_Patch"
}
}
英文:
Use a simple if
statement to add to one or the other:
Get-WsusServer | Get-WsusComputer -NameIncludes "wik" -ComputerTargetGroups "Unassigned Computers" | ForEach-Object {
if ($_.Computer -like '*xwik*'){
$_ | Add-WsusComputer -TargetGroupName "DMZ_Patch"
}
else {
$_ | Add-WsusComputer -TargetGroupName "Friday_Patch"
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论