[POWERSHELL] Escaneando en busca de RPC con Powershell

Iniciado por 79137913, Agosto 30, 2021, 11:20:36 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

HOLA!!!

Alguna vez les paso tener que arreglar el problema de "RPC Unavailable" error 1722?, que siempre queda mal en nuestros scripts de active directory o el Configuration manager (ademas de otros lados)ts

Para prevenir esto cree este script que permite verificarlo en batch por servidor, asi no estamos siempre con los mismos problemas de firewall o configuracion.


Sin mas preambulo el codigo:
Código: text

#  Como ejecutar:  RPCCheck -Server NombreDelServidorAqui
#
#  Requerimientos:  portqry.exe (de Sysinternals).
#  El path a portqry.exe tendra que reflectar la ubicacion del script.
#
Param(
[string]$Server
)

workflow Check-Port {
param ([string[]]$RPCServer,[array]$arrRPCPorts)
$comp = hostname

ForEach -parallel ($RPCPort in $arrRPCPorts)
{
$bolResult = InlineScript{Test-NetConnection -ComputerName $Using:RPCServer -port $Using:RPCPort _
-InformationLevel Quiet}
If ($bolResult)
{
Write-Output "$RPCPort en $RPCServer esta disponible"
}
Else
{
Write-Output "$RPCPort en $RPCServer no esta disponible "
}
}
}
$strRPCPort = "135"
#  MODIFICAR ESTE PATH A LA CARPETA DE SYSINTERNALS
$strPortQryPath = "C:\Sysinternals"
If (Test-Path "$strPortQryPath\PortQry.exe")
{
$strPortQryCmd = "$strPortQryPath\PortQry.exe -e $strRPCPort -n $Server"
}
Else
{
Write-Output "Could not locate Portqry.exe at the path $strPortQryPath"
Exit
}
$arrPorts = @()
$arrQuryResult = Invoke-Expression $strPortQryCmd
ForEach ($strResult in $arrQuryResult)
{
If ($strResult.Contains("ip_tcp"))
{
$arrSplt = $strResult.Split("[")
$strPort = $arrSplt[1]
$strPort = $strPort.Replace("]","")
$arrPorts += $strPort
}
}
$arrPorts = $arrPorts | Sort-Object |Select-Object -Unique
Check-Port -RPCServer $Server -arrRPCPorts $arrPorts


Atención:

Tienen que instalar PortQry.
Tendran que escribir el Path del PortQry.exe en esta linea del script: $strPortQryPath = "C:\Sysinternals"
Ademas necesitan PowerShell v4
PortQry.exe se descarga de No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

GRACIAS POR LEER!!!
"Algunos creen que soy un bot, puede que tengan razon"
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

*Shadow Scouts Team*                                                No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

¡Volvió números!

Gracias por el aporte  ;D

~ DtxdF
PGP :: <D82F366940155CB043147178C4E075FC4403BDDC>

~ DtxdF