Last active
May 22, 2019 16:08
Star
You must be signed in to star a gist
Trae todos los usuarios que estén dentro del grupo de administrador local en una lista de equipos. Funciona con servidores en Ingles, Español y Portugués.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import-module activedirectory | |
$ruta=get-location | |
$prueba=@() | |
$completo=0 | |
## la subred que se quiere buscar | |
$mascara="172.16.*" | |
cd "AD:\" | |
$equipos= Get-ADComputer -Filter {OperatingSystem -like "*server*"} -Properties ipv4address, CanonicalName, operatingsystem | Where-Object {$_.ipv4address -like $mascara} | |
$total=$equipos.count | |
foreach ($compu in $equipos){ | |
$nombre=$compu.name | |
$laip=$compu.ipv4address | |
$canonico=$compu.canonicalname | |
$OS=$compu.operatingsystem | |
$online=$false | |
$idioma=" " | |
$admicompleto=@() | |
$administradores="ERROR DESCONOCIDO" | |
$sacoadmin=$false | |
$adminroto=$false | |
$primero=$true | |
$agregar=" " | |
$online = Test-Connection $nombre -Quiet -count 1 | |
if ($online){ | |
## Esta online | |
$coso=get-wmiobject -ComputerName $nombre win32_operatingsystem | |
if(!$?){ | |
$idioma="999999" | |
}else{ | |
$idioma=$coso.oslanguage | |
} | |
Switch ($idioma){ | |
"3082" { | |
#Español Int | |
$admicompleto= Invoke-Command -ComputerName $nombre -ScriptBlock {net localgroup administradores} | |
if($?){ | |
$sacoadmin=$true | |
}else{ | |
$adminroto=$true | |
} | |
break | |
} | |
"1033" { | |
#Ingles US | |
$admicompleto= Invoke-Command -ComputerName $nombre -ScriptBlock {net localgroup administrators} | |
if($?){ | |
$sacoadmin=$true | |
}else{ | |
$adminroto=$true | |
} | |
break | |
} | |
"1046" { | |
#Portugues bra | |
$admicompleto= Invoke-Command -ComputerName $nombre -ScriptBlock {net localgroup administradores} | |
if($?){ | |
$sacoadmin=$true | |
}else{ | |
$adminroto=$true | |
} | |
break | |
} | |
"999999" { | |
# Si dio error en el get idioma | |
$administradores="ERROR DE WMI" | |
$sacoadmin=$false | |
break | |
} | |
Default { | |
# No se encuentra el codigo de idioma | |
$administradores="NO SE PUDO RESOLVER EL CODIGO $idioma" | |
$sacoadmin=$false | |
break | |
} | |
} | |
if($sacoadmin){ | |
## Ejecuto bien el proceso de admin | |
for($a=6;$a -lt ($admicompleto.count -2);$a++){ | |
if ($primero){ | |
$primero=$false | |
$agregar=$admicompleto[$a] | |
$administradores="$agregar" | |
} | |
else{ | |
$agregar=$admicompleto[$a] | |
$administradores+=", $agregar" | |
} | |
} | |
} | |
if($adminroto){ | |
##no ejecuto el proceso de admin por un error | |
$administradores="ERROR DE EJECUCION REMOTA" | |
} | |
}else{ | |
## No esta online | |
$idioma="NO DISPONIBLE" | |
$administradores="NO DISPONIBLE" | |
} | |
$PRUEBA+=$compu | select-object @{Expression={$nombre};Label="Nombre"}, @{expression={$online};label="Online"}, @{expression={$laip};label="IP"}, @{expression={$OS};label="OS"}, @{expression={$canonico};label="OU"}, @{Expression={$idioma};Label="Idioma"},@{expression={$sacoadmin};Label="ProcesoAdmins"} ,@{expression={$administradores};Label="Administradores"} | |
} | |
cd $ruta | |
$archivo="./reporte admin "+$mascara.Replace('*','x')+".csv" | |
$prueba | export-csv $archivo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment