Showing posts with label POWERSHELL. Show all posts
Showing posts with label POWERSHELL. Show all posts

Tuesday, May 20, 2025

Windows Update Button / Option disappear - update from powershell

 An old problem has started popping up recently on Windows PCs after certain updates. I have seen this on Win11, but mostly on Win10 PCs. Updates stop, Windows update search button disappears and the actual circling double flash windows update sign shows an exclamation mark, that something is not right.

No panic ! Instead of trying all sorts of stuff of get that back, you just need to be patient. The next couple of updates will be  probably correcting this issue and your windows update button and the appearance of Win update page will be the same.
However, there might be some steps to do, before you can launch your update. I really recommend, that instead of messing up your registry, searching for third party Non-MS solutions, uninstalling and re-installing updates, drivers, direct-x and more, you just do a full on windows repair, then update your current system.

Start by launching this script. You can copy it to ISE, or right click launch it as admin. Make sure that script execution is allowed. Just search in the search-bar: "script execution":
https://github.com/iv3l/PowerSHell-Scripts/blob/main/disable-non-essential-services.ps1

I have written it to stop non essential services for the being of all operations. After each restart, you need to launch it, as it won't disable the services, but stop them for the current session.

The you launch a dism and an sfc, then a reboot. These 3 commands one after another:

DISM /Online /Cleanup-Image /RrestoreHealth
sfc / scannow
shutdown /r /t 0

Depending on a lot of things like, how long have been the windows installed and untreated, on your network connection, speed of your disk and nvme drive, cpu, memory, space available, DISM might be slow, and it might take 2hours. For me on the I9 185h with GEN4 NVME and 32gb LPDDRX 6400 it takes around 1 to 2 minutes as an example.

Your PC has been restarted, now you reuse the firs script to stop services. Also please stop all non essential software too. You need to stop Dropbox, GDrive, Sticky Notes, Outlook, alll and everything.

The next thing is to update all your firmware. Most employees doesn't care about firmware updates and then they got their PC stop after an update. An OS install will fail. The PC will have program compatibility issues, like an endpoint manager will freeze the PC if running with the latest updated Ms Office package. These weird mishaps never happen on Linux, but Windows is an extremely sensitive system. All sorts of issues pop up if your system is not upgraded, but also it slows your system down. It can make updating your system the next time hell too, if you did not do anything for 2 years. I have systems with 100Gigs of obligatory windows update, just to be enough up to date on Win10, to be able to migrate to Win11. I mean with a connection speed of 2 to 20Mbps, this might take basically a week. I must keep these PCs intact, cannot just wipe them.

Now, that your firmware is updated and your PC is restarted, you run the first script again, to stop all non essential services. Then you again stop all of your programs. Here is a second script that will prompt you to install the updates. Again run ISE as admin or run the .ps1 script as admin. Your choice:
https://github.com/iv3l/PowerSHell-Scripts/blob/main/prompted_win_update.ps1

The script normally covers the installation of dependencies and initial calls of modules, but it might fail. Though it never happened to me. If you don't download it but copy it, make sure that that comments are in good condition as in some cases they do not show up as commented lines and launch as commands, what can be scary at first, giving you red error messages. 

I case you don't want to mess around with my script, you can download and install the updates yourself, running these in powershell, one after another:

Step-by-step:

a. Open PowerShell as Administrator, then install the module:

Install-Module -Name PSWindowsUpdate -Force

b. Import the module (if needed):

Import-Module PSWindowsUpdate

c. Check for updates:

Get-WindowsUpdate

d. Install updates:

Install-WindowsUpdate -AcceptAll -AutoReboot

This way you won't need to worry about your graphical interface based windows update, until the option comes back and your windows will do update itself. After the initial SFC and DISM commands, verify that you might already got back your win button. If not, wait for the KB corrections and major updates. IT might take one or 5. Run these each Wednesday and each Sunday morning.

Saturday, May 17, 2025

INSTALL GITHUB IN POWERSHELL

 Storing and accessing your work anywhere is great. You can use a blogging platform, cloud storage like dropbox, proton drive, or you can simply have a usb key. I am now to github and gits, I don't yet 100% get the concept, probably because I don't do programming, versioning, roll backs and don't work in groups either. I have been using gists for a while for publishing my work done on hackropole projects. 

https://gist.github.com/iv3l

However, for work I need to use batch scripts and powershell scripts outside of simple commands, than I also am working on an opensource infrastructure project that I will try documenting there too. 

So, if I understand well, we can have a sort of shared directory on the PC, that is synchronising with github, so we can have always the latest up to date data available. We also can pull data if needed. I beleive that at this moment, this is a very shallow understanding of the power of gits, but we have to start somewhere.
Of course, you need to create a github account before and also it is recommended to get familiar with the actual interface.

So let's install this into powershell:

winget install --id Git.Git -e --source winget

After relaunching powershell, verify with this cmd, that all good:

git --version

Check if it is really on your path:

$env:PATH -split ';' | Select-String git
 

Import a git library and make it syncro:
( first create a new repo on github, so you have something to install on your pc: mine is : Powershell Scripts) 
(go to your desired directory)

git clone https://github.com/your-username/powershell-scripts.git

To syncro your directory with github:

  • git add .
  • git commit -m "Add initial PowerShell scripts"
  • git push origin main

 

 

 

Manual Windows Update From PowerShell

I am so used to linux that I was looking for a simple solution in windows to do $ sudo apt update -y && sudo apt upgrade -y . From Powershell or from commandline. 

Normally first we must install the windows update module. Then load it into powershell. Then Launch it to search, then launch it to update . A little more complicated, a little longer and way slower than apt update and apt upgrade. But it works. 

Step-by-step:

a. Open PowerShell as Administrator, then install the module:

Install-Module -Name PSWindowsUpdate -Force

b. Import the module (if needed):

Import-Module PSWindowsUpdate

c. Check for updates:

Get-WindowsUpdate

d. Install updates:

Install-WindowsUpdate -AcceptAll -AutoReboot

You can also skip the reboot:

Install-WindowsUpdate -AcceptAll -IgnoreReboot

In some cases, when windows update in GUI doesn't want to install or it causes problems, stops, misbehaves, in powershell we can still run them. 

 

HERE IS A POWERSHELL SCRIPT FOR A FULL ON UPDATE PROCEDURE

Please allow script execution before !

 
 # Ensure script can run by temporarily setting execution policy
Try {
    $currentPolicy = Get-ExecutionPolicy -Scope Process
    If ($currentPolicy -ne 'Bypass') {
        Write-Host "[INFO] Setting execution policy to Bypass for this session..."
        Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
    }
} Catch {
    Write-Host "[ERROR] Failed to set execution policy: $_"
    Exit 1
}

Function Write-Log {
    param([string]$Message)
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    Write-Host "[$timestamp] $Message"
}

# Check for admin privileges
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Log "ERROR: Please run this script as Administrator."
    Exit 1
}

Write-Log "Starting Windows update check..."

# Ensure NuGet and PSWindowsUpdate
Try {
    If (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
        Write-Log "Installing NuGet..."
        Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
    } else {
        Write-Log "NuGet already present."
    }

    If (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
        Write-Log "Installing PSWindowsUpdate module..."
        Install-Module -Name PSWindowsUpdate -Force -Scope CurrentUser
    } else {
        Write-Log "PSWindowsUpdate module already present."
    }

    Import-Module PSWindowsUpdate -Force
    Write-Log "Module imported. Checking for updates..."

    $updates = Get-WindowsUpdate

    If ($updates.Count -eq 0) {
        Write-Log "No updates available. Your system is up to date."
        Exit 0
    }

    Write-Log "The following updates are available:"
    $updates | ForEach-Object { Write-Log " → $($_.Title)" }

    # Prompt the user
    $confirmation = Read-Host "`nDo you want to install these updates now? [Y/n]"

    If ($confirmation -eq "Y" -or $confirmation -eq "y" -or $confirmation -eq "") {
        Write-Log "Installing updates..."
        Install-WindowsUpdate -AcceptAll -AutoReboot -Verbose
        Write-Log "Updates installed. Reboot may occur automatically."
    } else {
        Write-Log "User cancelled update installation."
        Exit 0
    }
}
Catch {
    Write-Log "ERROR: $_"
    Exit 1
}

Iperf for Network monitoring

 IPERF is a very simple command line tool the check network quality between two PCs. Client - Server. There are options for stressing the te...