OSD icon indicating copy to clipboard operation
OSD copied to clipboard

Currently when editing startnet.cmd, it can be a pain & takes time i propose the following

Open Abe-Telo opened this issue 11 months ago • 6 comments

Proposal for Automating Script Execution in WinPE I recommend adding functionality to startnet.cmd to automatically search for and execute scripts located in a specific directory. Here's my proposed approach:

Directory Setup: If there is a folder located at Drive:\OSDCloud\Config\AutoWinPE, any scripts found in this folder should be executed automatically when WinPE starts.

Supported File Types: Files with the following extensions will be executed:

  • .cmd
  • .bat
  • .ps1

Priority Execution: To execute files in a specific order, name them with an underscore followed by a priority number. For example:

  • Run_1.cmd
  • WiFi.ps1
  • Hello_4.bat

Note: If no priority is defined, scripts will execute in a random order. If both priority and non-priority scripts exist, the priority scripts will run first, followed by the non-priority scripts.

Default Script Execution in startnet.cmd: Add the following to startnet.cmd to initiate PowerShell execution:

powershell.exe -ExecutionPolicy Bypass -File "X:\OSDCloud\Powershell\AutoWinPE.ps1" Alternatively:

powershell.exe -ExecutionPolicy Unrestricted -File "X:\OSDCloud\Powershell\AutoWinPE.ps1"

Skip Process if Directory is Empty: If no scripts are found in Drive:\OSDCloud\Config\AutoWinPE, skip the execution process entirely.

PowerShell Implementation Below is the PowerShell script to handle the execution logic:


# Function to execute scripts based on their file extension
function Run-ScriptBasedOnExtension {
    param (
        [string]$FilePath
    )
    $Extension = [System.IO.Path]::GetExtension($FilePath).ToLower()
    switch ($Extension) {
        ".bat" {
            Write-Host "Executing batch script: $FilePath"
            & $FilePath
        }
        ".cmd" {
            Write-Host "Executing command script: $FilePath"
            & $FilePath
        }
        ".ps1" {
            Write-Host "Executing PowerShell script: $FilePath"
            powershell.exe -NoProfile -ExecutionPolicy Bypass -File $FilePath
        }
        default {
            Write-Host "Unsupported file type: $FilePath"
        }
    }
}

# Locate the AutoWinPE folder
$OSDCloudAutoWinPE = Get-PSDrive -PSProvider FileSystem | Where-Object { Test-Path "$($_.Root)OSDCloud\Config\AutoWinPE" } | Select-Object -ExpandProperty Name

# If the folder exists
if ($null -ne $OSDCloudAutoWinPE) {
    $AutoWinPEPath = "$($OSDCloudAutoWinPE):\OSDCloud\Config\AutoWinPE\"
    Write-Host "AutoWinPE folder found at $AutoWinPEPath"

    # Get all scripts in the folder
    $Scripts = Get-ChildItem -Path $AutoWinPEPath -Filter "*.*" -Recurse

    # Identify priority scripts (_1, _2, _3, etc.)
    $PriorityScripts = $Scripts | Where-Object { $_.Name -match "_\d+" } | Sort-Object { [int]($_.BaseName -replace ".*_(\d+).*", '$1') }

    # Execute priority scripts
    if ($PriorityScripts.Count -gt 0) {
        Write-Host "Executing priority scripts:"
        foreach ($Script in $PriorityScripts) {
            Write-Host "Running priority script: $($Script.FullName)"
            Run-ScriptBasedOnExtension $Script.FullName
        }
    }

    # Execute non-priority scripts
    $NonPriorityScripts = $Scripts | Where-Object { $_.Name -notmatch "_\d+" }
    if ($NonPriorityScripts.Count -gt 0) {
        Write-Host "Executing non-priority scripts:"
        foreach ($Script in $NonPriorityScripts) {
            Write-Host "Running non-priority script: $($Script.FullName)"
            Run-ScriptBasedOnExtension $Script.FullName
        }
    }
} else {
    Write-Host "AutoWinPE folder not found. Skipping script execution."
}

Abe-Telo avatar Jan 27 '25 04:01 Abe-Telo

After spending years trying to standardize some things in OSDCloud, I have accepted the fact that not everyone will want to do things the same way. So while most people are probably ok with how things work, a few may want to do things the way you propose, but again, probably not everyone. Keep in mind I have a fixed amount of time I can spend adding customizations, as much time is involved with keeping DriverPacks up to date, or WinPE CloudDrivers functional (this is going away soon).

That said, is it your goal to customize Startnet.cmd so you can have WinPE startup the way you want it to? If that's correct, you can already do this with Edit-OSDCloudWinPE by adding your own Startnet as a String, exactly how you want it, although the process leaves much to be desired.

OSDeploy avatar Jan 27 '25 05:01 OSDeploy

That said, in the near future, you'll be able to select your own custom Startnet.cmd to inject into WinPE, which should satisfy your proposal as you can customize and implement this functionality on your own (see screenshot)

Image

OSDeploy avatar Jan 27 '25 05:01 OSDeploy

This is exciting news. I will wait for this implantation. Looking forward for this new enhancement. Thank you again for more new amazing feature's that enhances our life.

Abe-Telo avatar Jan 27 '25 05:01 Abe-Telo

Ok, I was a bit confused with your "This is existing news." I suppose you mean "This is exciting news." ??

OSDeploy avatar Jan 27 '25 06:01 OSDeploy

@Abe-Telo I couldn't help but notice this Repo of yours https://github.com/Abe-Telo/ODSCloud-Missing-Microsoft-Drivers

I suppose this new feature (coming soon) should solve your problem there as well?

Image

OSDeploy avatar Jan 27 '25 06:01 OSDeploy

@Abe-Telo I couldn't help but notice this Repo of yours https://github.com/Abe-Telo/ODSCloud-Missing-Microsoft-Drivers

I suppose this new feature (coming soon) should solve your problem there as well?

I use that for my company, I wasn't planning on merging it into OSDCloud unless you see something you like? Your more then welcome to take it into OSDCloud.

The reason i don't mess with OSDCloud, I get overwhelmed with the functions. I don't understand the layout fully, I always assumed everything is in the public directory. however i didn't feel confident to create something for the public. However i created scripts to lead as example that others can do.

It started off with the issues i was having in WinPE where Touch or keyboard drivers would not work. This issue was related to Edit-OSDCloud.winpe -CloudDriver * Not all drivers worked. The real solution here would be is to resolve it directly in WinPE. My Workaround code will get the model of the device, And based on that download the drivers while booting. If the device is online it will download the newly Github locally on the drive, and if your offline, It will use the Offline drivers that was downloaded in the past.

I then created more tools and script, I will explain each one of them. Maybe you will decide to use some of them.

  1. winpe_buttons.ps1 This can be useful with some modifications. (This script creates a button on the bottom right corner) that will open KeyBoard or WirelessConnect in WinPE

Image

  1. reinstall-preinstalledApps.ps1 This Script is very useful, at times you install windows and for reasons such as Windows is not activated or whatever reasons, MS Store or MS Apps will be missing, Running that brings everything back to life.

  2. Sometimes in windows 11 the explorer would freeze up or the task bar would act weird. in Images.zip there is a script that when you run it it resolves the issue immediately.

  3. GSFORM.PS1 A simple Script that logs all your SN and PC info into Google sheet, I since created a full backend system and no longer use it. ( I don't see anyone needing this)

Those are the things that are currently online, But i have more scripts offline that i plan to update when i have a chance. If there is anything valuable to you, You more then welcome to either guild me or use it.

Update Aww and after writhing all this, I realized that you where saying that i wont need that script anymore lol That's even more great news. Thank you again.

Abe-Telo avatar Jan 27 '25 06:01 Abe-Telo