Wsus 和 PowerShell

huangapple go评论61阅读模式
英文:

Wsus and powershell

问题

I would like to know if it is possible to move computers in a group from a csv or txt list ...

the script below machine by machine
Get-WsusServer -Name "contoso" | Get-WsusComputer -NameIncludes "winvm" | Add-WsusComputer -TargetGroupName "Windows Virtual Machines"
thx a lot

Get-WsusServer -Name "contoso" | Get-WsusComputer -NameIncludes (Get-Content D:\pc.txt) | Add-WsusComputer -TargetGroupName "Windows Virtual Machines";

But it does not work.

英文:

I would like to know if it is possible to move computers in a group from a csv or txt list ...

the script below machine by machine
Get-WsusServer -Name "contoso" | Get-WsusComputer -NameIncludes "winvm" | Add-WsusComputer -TargetGroupName "Windows Virtual Machines"
thx a lot

Get-WsusServer -Name "contoso" | Get-WsusComputer -NameIncludes (Get-Content D:\pc.txt) | Add-WsusComputer -TargetGroupName "Windows Virtual Machines"

But it does not work

答案1

得分: 1

当我编写计算机分配脚本时,我也将虚拟机放在不同的计算机组中,而不是物理主机。除此之外,我还进行了更多操作,解析机器名称以确定位置,因为我们在计算机命名架构中包含了地区标识符,但如果只是根据是否为虚拟机,你可以这样做:

Import-Module UpdateServices
$WSUS = Get-WsusServer
$AllGroups = $WSUS.GetComputerTargetGroups()
$VMGroup = $AllGroups.Where({$_.Name -eq 'Windows Virtual Machines'})
$AllComputers = $Groups.Where({$_.Name -eq 'All Computers'}).GetComputerTargets()
$ComputerList = Get-Content D:\pc.txt
$AllComputers.Where({$_.Model -eq 'Virtual Machine'})|ForEach-Object{
    $VMGroup.AddComputerTarget($_)
}

或者,如果你想根据文件中的计算机列表进行操作:

$AllComputers.Where({$_.Name -in $ComputerList})|ForEach-Object{
    $VMGroup.AddComputerTarget($_)
}
英文:

When I scripted out computer assignments I too put VMs in a different computer group than physical hosts. I did a bit more than that parsing machine names to determine location since we put regional identifiers in our computer naming schema, but just going off if something is a VM you could do this:

Import-Module UpdateServices
$WSUS = Get-WsusServer
$AllGroups = $WSUS.GetComputerTargetGroups()
$VMGroup = $AllGroups.Where({$_.Name -eq 'Windows Virtual Machines'})
$AllComputers = $Groups.Where({$_.Name -eq 'All Computers'}).GetComputerTargets()
$ComputerList = Get-Content D:\pc.txt
$AllComputers.Where({$_.Model -eq 'Virtual Machine'})|ForEach-Object{
    $VMGroup.AddComputerTarget($_)
}

Or if you want to go off a list of computers in a file:

$AllComputers.Where({$_.Name -in $ComputerList})|ForEach-Object{
    $VMGroup.AddComputerTarget($_)
}

答案2

得分: -1

谢谢你,TheMadTechnician。

事实上,机器按组进行分类,例如:
组A = win10 和组B = W11-21-H2
组C = Win11 22-H2,目标是一次性掌握组C中列表中的若干台机器。

英文:

Thank you so much TheMadTechnician

in fact, the machines are classified by group, for example:
group A= win10 and group B= W11-21-H2
Group C=Win11 22-H2, the goal is to master a certain number of machines in Group C from the list at once

huangapple
  • 本文由 发表于 2023年3月21日 00:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定