Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Script o cmdlet en PowerShell para agregar o mover equipos a un grupo del WSUS (sin SSL), a partir de un listado de equipos, en un archivo de texto.
- #El script necesita Permisos de administrador y tener instalada la consola del WSUS en la maquina local donde se ejecuta el script.
- Más info > http://jogacrack.co/2012/08/17/administrar-wsus-powershell-scripts-windows
- ------------------------------------
- #Inicializar variables
- $wsusGroup = [string] "GrupoparaMoverLosEquipos"
- $date = get-date
- $date = [string] $date.day + $date.month + $date.year + $date.hour + $date.minute
- $succeslog = [string] ".\logs\" + $date + "_success.log"
- $errorlog = [string] ".\logs\" + $date + "_errors.log"
- $WindowsUpdateServer= [string] "NombreServerWSUS"
- #Inicializar Objetos:
- #Requiere la consola del WSUS instalada con las herramientas administrativas.
- [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
- if (!$wsus) {
- $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WindowsUpdateServer,$False)
- }
- $serverList = Get-Content ".\listadoequipos.txt"
- $updateGroups = $Wsus.GetComputerTargetGroups()
- $updateGroup = $UpdateGroups | Where-Object{$_.Name -eq $wsusGroup}
- $computerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
- $computerScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
- $computers = $wsus.GetComputerTargets($computerScope)
- $wsusServers = @()
- $WsusServersShortNames = @()
- #Crear arrays (estructura de datos):
- # $wsusServer = Array de los objetos (equipos) del WSUS.
- # $wsusServerShortName = Cadena de Arrays, con un servidor RDN por línea
- Write-Host "Recolectando lista de los equipos desde el WSUS"
- $computers | foreach-object {
- $wsusServer = $_.FullDomainName
- $wsusServerShortName = $WsusServer.split(‘.’)[0]
- $wsusServers += $WsusServer
- $wsusServersShortNames += $wsusServerShortName
- } #Fin del ciclo For de los equipos
- #Ciclo FOR para agregar o mover los equipos al grupo en el WSUS
- ForEach ($server in $serverList) {
- #Chequear si el nombre Netbios de los equipos esta en el WSUS, si esta se mueve sino genera el error y lo escribe en el LOG.
- $wsusComputer = $wsusServersShortNames | Where-Object {$_ -eq $server.Trim()}
- If ($wsusComputer) {
- $searchStr = [string] $server.Trim() + "\."
- $wsusComputer1 = $wsusServers | where-object {$_ -match $searchStr }
- If ($wsusComputer1.getType().Name -match "string") {
- Write-Host "$wsusComputer1 se agregara al grupo $($updateGroup.name) "
- $computer = $wsus.GetComputerTargetByName($wsusComputer1)
- $updateGroup.AddComputerTarget($computer)
- out-file -append -inputobject "$Server agregado al grupo $($updategroup.name) " -filepath $succeslog
- }
- Else {
- write-host "count $($wsusComputer1.count)"
- Out-File -append -inputobject "$Server el nombre es ambiguo, por favor verifique en el WSUS y agregue el equipo manualmente" -filepath $errorlog
- }
- } #Fin del si $wsusComputer
- Else {
- Write-Host "$Server no encontrado en el WSUS"
- out-file -append -inputobject "$Server no encontrado en el WSUS" -filepath $errorlog
- }
- } #End ForEach $server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement