meta data de esta página
  •  

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Próxima revisión
Revisión previa
windows:powershell:pswindowsupdate [2022/05/11 10:07] – creado lcwindows:powershell:pswindowsupdate [2023/05/11 09:33] (actual) – [Referencias] lc
Línea 1: Línea 1:
 ===== Actualizar estaciones usando PowerShell ===== ===== Actualizar estaciones usando PowerShell =====
 +==== Actualizar Windows ====
 +Lo primero es ejecutar powershell desde una consola administrador. Para lanzar powershell desde la línea de comandos como administrador
 +<sxh ps>powershell Start-Process powershell -Verb runAs</sxh>
 +
 +=== Configurar el proxy si es necesario ===
 +Dentro de poweshell si usamos proxy debemos de especificar primero el mismo
 +<sxh>netsh winhttp set proxy "miproxy:puerto"</sxh>
 +o bien
 +<sxh>netsh winhttp import proxy source=ie</sxh>
 +
 +== Otra forma de poner el proxy ==
 +<sxh ps>
 +$proxy = '172.19.254.2:8080'
 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
 +[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($proxy)
 +[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
 +</sxh>
 +
 +También podemos añadirlo en nuestro perfil añadiendo las siguientes líneas al mismo, abrimos el perfil 
 +<sxh>notepad $PROFILE</sxh>
 +Añadimos al PROFILE las siguientes líneas:
 +
 +<sxh ps>
 +[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://miproxy:mipuerto')
 +[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
 +[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
 +</sxh>
 +
 +
 +=== Configurar para que se use TLS1.2 ===
 +<sxh ps>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12</sxh>
 +
 +
 +=== Para quitarlo ===
 +<sxh>netsh winhttp reset proxy</sxh>
 +
 +
 +=== Comprobación ===
 +Para hacer una prueba y comprobar si tenemos acceso a internet
 +<sxh ps>Invoke-WebRequest google.es</sxh>
 +
 +
 +=== Instalar NuGet ===
 +<sxh ps>Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force </sxh>
 +
 +Como daba problemas al final a mi me ha funcionando con 
 +<sxh ps>Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -proxy 'http:\\172.19.254.2:8080' </sxh>
 +
 +
 +Con <sxh ps>Get-PackageProvider -ListAvailable</sxh> podemos ver los paquetes que tenemos instalados
 +
 +=== Registrar el repositorio PSGallery ===
 +<sxh>Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted </sxh>
 +
 +
 +
 +=== Instalar el módulo PSWindowsUpdate ===
 +<sxh ps>Install-Module PSWindowsUpdate</sxh>
 +
 +Si te da error mirar https://www.sysadmit.com/2021/11/windows-powershell-error-instalar-nuget.html
 +
 +== Importamos el módulo a la sesión actual ==
 +<sxh ps>Import-Module PSWindowsUpdate</sxh>
 +
 +== error porque está deshabilitada la ejecución de scripts ==
 +Si al ejecutar algún comando nos da error de que no pudo cargarse es probable que tenga restringida la ejecución de scripts
 +
 +Para saber que política se aplica en el equipo ejecutamos 
 +<sxh ps>Get-ExecutionPolicy</sxh>
 +
 +Para cambiar la política 
 +<sxh ps>Set-ExecutionPolicy -ExecutionPolicy <políticanueva></sxh>
 +
 +Por ejemplo
 +<sxh ps>Set-ExecutionPolicy -ExecutionPolicy RemoteSigned</sxh>
 +
 +== Comandos del módulo ==
 +  * Para saber todos los comandos del módulo ejecutar -> **Get-Command –Module PSWindowsUpdate**
 +  * Ver las opciones configuradas->**Get-WUSettings**
 +  * Ver las actualizaciones pendientes→ **Get-WindowsUpdate o Get-WUList**
 +  * Ver la última vez que actualizó` (New-Object -com "Microsoft.Update.AutoUpdate").Results|fl`
 +  * Instalar las actualizaciones → **Install-WindowsUpdate**
 +  * Instalar y reinciar **Install-WindowsUpdate -AcceptAll -AutoReboot**
 +  * Instalar un KB específico → **Get-WindowsUpdate -Install -KBArticleID 'KB4560960'**
 +
 +
 +=== Ver la fecha de la última actualización ===
 +<sxh ps>(New-Object -com "Microsoft.Update.AutoUpdate").Results|fl</sxh>
 +
 +https://www.sysadmit.com/2019/03/windows-update-ver-fecha-powershell.html
 +
 +=== Para saber si necesita reiniciar ===
 +<sxh ps>Get-WURebootStatus</sxh>
 +=== Historial de Actualizaciones ===
 +<sxh ps>Get-WUHistory</sxh>
 +
 +<sxh ps>Get-WUInstallerStatus</sxh>
 +
 +
 +Para ver la versión del sistema operativo ejecutar <sxh>systeminfo</sxh> desde la línea de comandos
 +
 +
  
 ===== Referencias ===== ===== Referencias =====
Línea 5: Línea 107:
   * http://woshub.com/pswindowsupdate-module/   * http://woshub.com/pswindowsupdate-module/
   * https://reparar.info/pswindowsupdate-administracion-de-actualizaciones-de-windows-desde-powershell/   * https://reparar.info/pswindowsupdate-administracion-de-actualizaciones-de-windows-desde-powershell/
 +  * https://adamtheautomator.com/powershell-run-as-administrator/
 +  * https://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/
 +  * https://reparar.info/usar-powershell-detras-de-un-servidor-proxy/
 +  * https://reparar.info/pswindowsupdate-administracion-de-actualizaciones-de-windows-desde-powershell/
 +  * https://adamtheautomator.com/pswindowsupdate/
 +  *  http://woshub.com/pswindowsupdate-module/
 +  * https://www.parallels.com/blogs/ras/powershell-windows-update/
 +  * https://blog.velingeorgiev.com/install-powershell-5-nuget-sharepointpnppowershellonline-behind-proxy
 +  * https://daveshap.github.io/DavidShapiroBlog/powershell/kb/2021/03/12/install-powershell-modules.html
 +  * https://spaghettidba.com/2017/12/19/recovering-the-psgallery-repository-behind-a-corporate-proxy/
 +  * https://docs.microsoft.com/es-es/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2
 +  * https://spaghettidba.com/2017/12/19/recovering-the-psgallery-repository-behind-a-corporate-proxy/