├── .DS_Store ├── Azure └── VPNPointSiteAzureCertificates.ps1 ├── README.md ├── Windows Cliente ├── BitlockerKeysRecoveryScript.ps1 ├── Check-KBInstallation.ps1 └── Install-OhMyPosh.ps1 └── Windows Server ├── ExportDNSRegisterAllZones.ps1 └── ValidateVBSScripts.ps1 /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyITPro/scripts/6c5693c709342a19711f7d9cf285d4ff3a756ba6/.DS_Store -------------------------------------------------------------------------------- /Azure/VPNPointSiteAzureCertificates.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Crea certificados para usar en VPNs de Azure. 4 | .DESCRIPTION 5 | Utiliza para crear el root certificate y client para las conexiones Punto a sitio de VPN en redes Azure. 6 | #> 7 | 8 | #RootCertificate 9 | $cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature ` 10 | -Subject "CN=P2SRootCert" -KeyExportPolicy Exportable ` 11 | -HashAlgorithm sha256 -KeyLength 2048 ` 12 | -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign 13 | 14 | #ClientCertificate 15 | New-SelfSignedCertificate -Type Custom -DnsName P2SChildCert -KeySpec Signature ` 16 | -Subject "CN=P2SChildCert" -KeyExportPolicy Exportable ` 17 | -HashAlgorithm sha256 -KeyLength 2048 ` 18 | -CertStoreLocation "Cert:\CurrentUser\My" ` 19 | -Signer $cert -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Este repositorio contiene una colección de scripts de PowerShell útiles para administración de sistemas, automatización de tareas y soluciones IT. Los scripts están organizados por categorías y listos para implementar en entornos Windows. 2 | 3 | ## 🚀 Características 4 | 5 | * 🛠️ Scripts listos para producción 6 | 7 | * 📝 Documentación clara para cada script 8 | 9 | * 🔍 Ejemplos de uso 10 | 11 | * ✔️ Probados en diferentes versiones de Windows Cliente (10,11) y Windows Server (2012,2016,2019,2022,2025) 12 | 13 | 14 | ## ⚙️ Requisitos 15 | * PowerShell 5.1 o superior 16 | 17 | * Módulos requeridos especificados en cada script 18 | 19 | * Permisos de ejecución de scripts (ejecutar Set-ExecutionPolicy RemoteSigned si es necesario) 20 | 21 | ```powershell 22 | Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force 23 | ``` 24 | 25 | ## 🤝 Contribuciones 26 | * ¡Contribuciones son bienvenidas! Por favor 27 | 28 | ## 📌 Mejores Prácticas para Scripts 29 | 30 | * Usar nombres descriptivos en inglés 31 | 32 | * Incluir comentarios y ayuda 33 | 34 | * Implementar manejo de errores 35 | 36 | * Probar en entorno controlado primero 37 | 38 | * Documentar requisitos y parámetros 39 | 40 | ## ⚠️ Advertencia 41 | 42 | > [!CAUTION] 43 | > Ejecuta estos Scripts bajo tu propio riesgo. Siempre revisa el código antes de ejecutarlo en sistemas de producción. 44 | 45 | 46 | -------------------------------------------------------------------------------- /Windows Cliente/BitlockerKeysRecoveryScript.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Obtiene claves de recuperación de BitLocker usando el módulo de PowerShell 4 | #> 5 | 6 | # Verificar e importar módulo BitLocker 7 | if (-not (Get-Module -Name BitLocker -ListAvailable)) { 8 | Write-Warning "Módulo BitLocker no disponible. Intentando cargarlo..." 9 | Import-Module BitLocker -ErrorAction SilentlyContinue 10 | } 11 | 12 | if (Get-Command -Name Get-BitLockerVolume -ErrorAction SilentlyContinue) { 13 | # Configurar archivo de salida 14 | $OutputFile = "C:\Temp\BitLockerKeys_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt" 15 | 16 | # Crear directorio si no existe 17 | if (-not (Test-Path -Path "C:\Temp")) { 18 | New-Item -ItemType Directory -Path "C:\Temp" | Out-Null 19 | } 20 | 21 | # Obtener volúmenes protegidos con BitLocker 22 | $volumes = Get-BitLockerVolume | Where-Object { $_.ProtectionStatus -eq "On" } 23 | 24 | if ($volumes) { 25 | $results = @() 26 | foreach ($vol in $volumes) { 27 | $protectors = Get-BitLockerVolume -MountPoint $vol.MountPoint | ` 28 | Select-Object -ExpandProperty KeyProtector | ` 29 | Where-Object { $_.KeyProtectorType -eq "RecoveryPassword" } 30 | 31 | foreach ($prot in $protectors) { 32 | $results += "[$($prot.KeyProtectorId)] $($prot.RecoveryPassword)" 33 | } 34 | } 35 | 36 | if ($results) { 37 | $results | Out-File -FilePath $OutputFile -Encoding UTF8 38 | Write-Host "Claves encontradas y guardadas en: $OutputFile" -ForegroundColor Green 39 | Get-Content $OutputFile 40 | } else { 41 | Write-Warning "No se encontraron protectores de clave de recuperación, pero BitLocker está activo." 42 | } 43 | } else { 44 | Write-Warning "No se encontraron volúmenes con BitLocker activado." 45 | } 46 | } else { 47 | Write-Error "No se pudo cargar el módulo BitLocker. Pruebe el Método 2." 48 | } -------------------------------------------------------------------------------- /Windows Cliente/Check-KBInstallation.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifica si los servidores listados tienen instalada una actualización específica por su KB ID. 4 | .DESCRIPTION 5 | Este script lee una lista de servidores desde un archivo .txt y verifica si cada uno tiene instalada 6 | la actualización de Windows especificada por su ID de Knowledge Base (KB). 7 | .PARAMETER ServersFile 8 | Ruta del archivo .txt que contiene la lista de servidores (uno por línea). 9 | .PARAMETER KBID 10 | ID de la actualización a verificar (ejemplo: "KB5005565"). 11 | .EXAMPLE 12 | .\Check-KBInstallation.ps1 -ServersFile "C:\servers.txt" -KBID " 13 | #> 14 | 15 | param ( 16 | [Parameter(Mandatory=$true)] 17 | [string]$ServersFile, 18 | 19 | [Parameter(Mandatory=$true)] 20 | [string]$KBID 21 | ) 22 | 23 | # Limpiar el KBID por si acaso viene con formato diferente (ej: KB5005565 o 5005565) 24 | $KBID = $KBID -replace "KB", "" # Elimina "KB" si está presente 25 | $KBID = $KBID.Trim() # Elimina espacios en blanco 26 | 27 | # Verificar si el archivo de servidores existe 28 | if (-not (Test-Path -Path $ServersFile)) { 29 | Write-Host "Error: El archivo $ServersFile no existe." -ForegroundColor Red 30 | exit 1 31 | } 32 | 33 | # Leer la lista de servidores 34 | try { 35 | $servers = Get-Content -Path $ServersFile | Where-Object { $_ -ne "" } 36 | } 37 | catch { 38 | Write-Host "Error al leer el archivo $ServersFile : $_" -ForegroundColor Red 39 | exit 1 40 | } 41 | 42 | if ($servers.Count -eq 0) { 43 | Write-Host "El archivo $ServersFile no contiene servidores válidos." -ForegroundColor Yellow 44 | exit 0 45 | } 46 | 47 | # Resultados 48 | $results = @() 49 | 50 | Write-Host "Verificando la actualizacion KB$KBID en $($servers.Count) servidores..." -ForegroundColor Cyan 51 | 52 | foreach ($server in $servers) { 53 | try { 54 | # Verificar si el servidor está accesible 55 | if (-not (Test-Connection -ComputerName $server -Count 1 -Quiet)) { 56 | Write-Host "[$server] No responde a ping" -ForegroundColor Yellow 57 | $results += [PSCustomObject]@{ 58 | Server = $server 59 | Status = "Offline" 60 | HotfixID = "N/A" 61 | InstalledOn = "N/A" 62 | Error = "No responde a ping" 63 | } 64 | continue 65 | } 66 | 67 | # Verificar el hotfix 68 | $hotfix = Get-HotFix -ComputerName $server -Id "KB$KBID" -ErrorAction SilentlyContinue 69 | 70 | if ($hotfix) { 71 | Write-Host "[$server] Actualizacion KB$KBID instalada el $($hotfix.InstalledOn)" -ForegroundColor Green 72 | $results += [PSCustomObject]@{ 73 | Server = $server 74 | Status = "Online" 75 | HotfixID = $hotfix.HotFixID 76 | InstalledOn = $hotfix.InstalledOn 77 | Error = "N/A" 78 | } 79 | } else { 80 | Write-Host "[$server] Actualizacion KB$KBID NO esta instalada" -ForegroundColor Red 81 | $results += [PSCustomObject]@{ 82 | Server = $server 83 | Status = "Online" 84 | HotfixID = "N/A" 85 | InstalledOn = "N/A" 86 | Error = "Actualizacion no encontrada" 87 | } 88 | } 89 | } 90 | catch { 91 | Write-Host "[$server] Error al verificar: $_" -ForegroundColor Red 92 | $results += [PSCustomObject]@{ 93 | Server = $server 94 | Status = "Error" 95 | HotfixID = "N/A" 96 | InstalledOn = "N/A" 97 | Error = $_.Exception.Message 98 | } 99 | } 100 | } 101 | 102 | # Mostrar resumen 103 | Write-Host "`nResumen de la verificacion:" -ForegroundColor Cyan 104 | $results | Format-Table -AutoSize 105 | 106 | # Exportar resultados a CSV 107 | $outputFile = "KB_Verification_Results_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv" 108 | $results | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8 109 | Write-Host "`nResultados exportados a $outputFile" -ForegroundColor Cyan -------------------------------------------------------------------------------- /Windows Cliente/Install-OhMyPosh.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Instala Oh My Posh y personaliza la terminal de Windows 11 4 | .DESCRIPTION 5 | Este script automatiza la instalación de Oh My Posh usando winget, 6 | instala una fuente compatible, configura el perfil de PowerShell 7 | y personaliza la apariencia de la terminal. 8 | .NOTES 9 | Versión: 1.1 10 | Autor: @SoyITPro 11 | #> 12 | 13 | # Requiere ejecución como administrador para instalar la fuente 14 | if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { 15 | Write-Host "Este script requiere privilegios de administrador para instalar la fuente." -ForegroundColor Red 16 | Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs 17 | exit 18 | } 19 | 20 | # Función para verificar si un comando existe 21 | function Test-CommandExists { 22 | param($command) 23 | $exists = $null -ne (Get-Command $command -ErrorAction SilentlyContinue) 24 | return $exists 25 | } 26 | 27 | # Verificar si winget está instalado 28 | if (-not (Test-CommandExists "winget")) { 29 | Write-Host "winget no está instalado. Por favor instala Windows Package Manager (App Installer) desde la Microsoft Store." -ForegroundColor Red 30 | exit 31 | } 32 | 33 | Write-Host "`n=== Instalando Oh My Posh ===" -ForegroundColor Cyan 34 | # Instalar Oh My Posh 35 | winget install JanDeDobbeleer.OhMyPosh -s winget --accept-package-agreements --accept-source-agreements 36 | 37 | Write-Host "`n=== Instalando fuente Meslo LGM NF ===" -ForegroundColor Cyan 38 | # Descargar e instalar la fuente Meslo LGM NF (compatible con iconos) 39 | $fontUrl = "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/Meslo.zip" 40 | $tempDir = [System.IO.Path]::GetTempPath() 41 | $fontZip = Join-Path $tempDir "Meslo.zip" 42 | $fontDir = Join-Path $tempDir "MesloFonts" 43 | 44 | # Descargar el archivo de fuentes 45 | Invoke-WebRequest -Uri $fontUrl -OutFile $fontZip 46 | 47 | # Extraer las fuentes 48 | if (-not (Test-Path $fontDir)) { 49 | New-Item -ItemType Directory -Path $fontDir -Force | Out-Null 50 | } 51 | Expand-Archive -Path $fontZip -DestinationPath $fontDir -Force 52 | 53 | # Instalar las fuentes 54 | $shell = New-Object -ComObject Shell.Application 55 | $fontsFolder = $shell.Namespace(0x14) 56 | 57 | Get-ChildItem -Path $fontDir -Recurse -Include "*.ttf" | ForEach-Object { 58 | $fontPath = $_.FullName 59 | $fontsFolder.CopyHere($fontPath, 0x10) 60 | } 61 | 62 | Write-Host "`n=== Configurando el perfil de PowerShell ===" -ForegroundColor Cyan 63 | # Crear el directorio del perfil si no existe 64 | if (-not (Test-Path $PROFILE)) { 65 | New-Item -ItemType File -Path $PROFILE -Force 66 | } 67 | 68 | # Configurar Oh My Posh en el perfil 69 | $ohMyPoshConfig = @" 70 | # Oh My Posh setup 71 | oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression 72 | 73 | # Aliases útiles 74 | Set-Alias -Name ll -Value Get-ChildItem 75 | Set-Alias -Name grep -Value Select-String 76 | 77 | # Colores personalizados 78 | `$Host.PrivateData.ErrorForegroundColor = "Red" 79 | `$Host.PrivateData.ErrorBackgroundColor = "Black" 80 | `$Host.PrivateData.WarningForegroundColor = "Yellow" 81 | `$Host.PrivateData.WarningBackgroundColor = "Black" 82 | `$Host.PrivateData.DebugForegroundColor = "Cyan" 83 | `$Host.PrivateData.DebugBackgroundColor = "Black" 84 | 85 | # Función para actualizar Oh My Posh 86 | function Update-Posh { 87 | winget upgrade JanDeDobbeleer.OhMyPosh -s winget --accept-package-agreements --accept-source-agreements 88 | oh-my-posh font install 89 | Write-Host "Oh My Posh actualizado correctamente." -ForegroundColor Green 90 | } 91 | "@ 92 | 93 | # Guardar la configuración en el perfil 94 | Set-Content -Path $PROFILE -Value $ohMyPoshConfig 95 | 96 | Write-Host "`n=== Configurando la Terminal de Windows ===" -ForegroundColor Cyan 97 | # Configuración JSON para la Terminal de Windows 98 | $terminalSettings = @" 99 | { 100 | "profiles": { 101 | "defaults": { 102 | "font": { 103 | "face": "MesloLGL Nerd Font", 104 | "size": 15 105 | }, 106 | "opacity": 85, 107 | "useAcrylic": true 108 | }, 109 | "list": [ 110 | { 111 | "commandline": "powershell.exe -NoExit -Command \", 112 | "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", 113 | "hidden": false, 114 | "name": "PowerShell Personalizado", 115 | "startingDirectory": "%USERPROFILE%" 116 | } 117 | ] 118 | }, 119 | "schemes": [ 120 | { 121 | "background": "#012456", 122 | "black": "#0C0C0C", 123 | "blue": "#0037DA", 124 | "brightBlack": "#767676", 125 | "brightBlue": "#3B78FF", 126 | "brightCyan": "#61D6D6", 127 | "brightGreen": "#16C60C", 128 | "brightPurple": "#B4009E", 129 | "brightRed": "#E74856", 130 | "brightWhite": "#F2F2F2", 131 | "brightYellow": "#F9F1A5", 132 | "cyan": "#3A96DD", 133 | "foreground": "#CCCCCC", 134 | "green": "#13A10E", 135 | "name": "Custom Blue", 136 | "purple": "#881798", 137 | "red": "#C50F1F", 138 | "white": "#CCCCCC", 139 | "yellow": "#C19C00" 140 | } 141 | ], 142 | "theme": "dark" 143 | } 144 | "@ 145 | 146 | # Guardar la configuración de la terminal 147 | $terminalSettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" 148 | if (Test-Path $terminalSettingsPath) { 149 | $backupPath = "$terminalSettingsPath.backup_$(Get-Date -Format 'yyyyMMddHHmmss')" 150 | Copy-Item -Path $terminalSettingsPath -Destination $backupPath -Force 151 | Write-Host "Se creó una copia de seguridad de la configuración actual en $backupPath" -ForegroundColor Yellow 152 | } 153 | 154 | Set-Content -Path $terminalSettingsPath -Value $terminalSettings 155 | 156 | Write-Host "`n=== Instalación completada ===" -ForegroundColor Green 157 | Write-Host "1. Oh My Posh ha sido instalado correctamente." 158 | Write-Host "2. La fuente Meslo LGM NF ha sido instalada." 159 | Write-Host "3. El perfil de PowerShell ha sido configurado." 160 | Write-Host "4. La Terminal de Windows ha sido personalizada." 161 | Write-Host "`nPor favor, cierra y vuelve a abrir la Terminal de Windows para ver los cambios." -ForegroundColor Yellow 162 | Write-Host "En la nueva terminal, selecciona 'PowerShell Personalizado' y configura la fuente MesloLGM NF en la configuración." -ForegroundColor Yellow -------------------------------------------------------------------------------- /Windows Server/ExportDNSRegisterAllZones.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Exportar registros DNS. 4 | .DESCRIPTION 5 | Este script exporta todos los registros DNS de todas las zonas DNS en el DNS Server de Windows Server 6 | .NOTES 7 | Author : @SoyITPro 8 | Prerequisite : PowerShell 5.1 o superior 9 | 10 | #> 11 | $dnsRecords = @() 12 | $zones = Get-DnsServerZone 13 | foreach ($zone in $zones) { 14 | $zoneInfo = Get-DnsServerResourceRecord -ZoneName $zone.ZoneName 15 | foreach ($info in $zoneInfo) { 16 | $timestamp = if ($info.Timestamp) { $info.Timestamp } else { "static" } 17 | $timetolive = $info.TimeToLive.TotalSeconds 18 | $recordData = switch ($info.RecordType) { 19 | 'A' { $info.RecordData.IPv4Address } 20 | 'CNAME' { $info.RecordData.HostnameAlias } 21 | 'NS' { $info.RecordData.NameServer } 22 | 'SOA' { "[$($info.RecordData.SerialNumber)] $($info.RecordData.PrimaryServer), $($info.RecordData.ResponsiblePerson)" } 23 | 'SRV' { $info.RecordData.DomainName } 24 | 'PTR' { $info.RecordData.PtrDomainName } 25 | 'MX' { $info.RecordData.MailExchange } 26 | 'AAAA' { $info.RecordData.IPv6Address } 27 | 'TXT' { $info.RecordData.DescriptiveText } 28 | default { $null } 29 | } 30 | $dnsRecords += [pscustomobject]@{ 31 | Name = $zone.ZoneName 32 | Hostname = $info.Hostname 33 | Type = $info.RecordType 34 | Data = $recordData 35 | Timestamp = $timestamp 36 | TimeToLive = $timetolive 37 | } -------------------------------------------------------------------------------- /Windows Server/ValidateVBSScripts.ps1: -------------------------------------------------------------------------------- 1 | #Valida en los Path si existen archivos .vbs 2 | 3 | $pathsToScan = @("C:\Users", "C:\ProgramData", "C:\Scripts") 4 | $logPath = "C:\VBSScriptScan\VbsFiles_$(hostname).csv" 5 | 6 | # Crear directorio si no existe 7 | if (-not (Test-Path (Split-Path $logPath -Parent))) { 8 | New-Item -ItemType Directory -Path (Split-Path $logPath -Parent) | Out-Null 9 | } 10 | 11 | $results = foreach ($path in $pathsToScan) { 12 | if (Test-Path $path) { 13 | Get-ChildItem -Path $path -Filter *.vbs -Recurse -ErrorAction SilentlyContinue | 14 | Select-Object FullName, LastWriteTime, Length 15 | } 16 | } 17 | 18 | $results | Export-Csv -Path $logPath -NoTypeInformation 19 | --------------------------------------------------------------------------------