Search code examples
powershellwindows-10unattended-processing

How do I add a powershell script to be run post setup during a windows 10 unattended install?


I may be going about this the wrong/more difficult way. I am open to suggestions.

I am running NTLite v2.3.8.8920 [HOME] ((c) NTlitesoft d.o.o) to create unattended Windows 10 discs. After years of doing unattended discs and realizing the ever expanding size of the disc, (Latest disc was 32.73GB!), I found WinGet, the absolutely amazing repository, and have even gone as far as to create my own installer!

The issue for today is: how do I access WinGet during an unattended installation? I have compiled a list of applications that I use frequently; most that I have been hard coding to the disc and thus this incredible size; and I would love to be able to run this script post-setup and save the time and space. Here is my code:

#The first batch here is a function I created for notification purposes.  Not sure how to do timed popups in Powershell yet.
#Get Words 
    function GW($myinput){
    $WS = New-Object -ComObject "Wscript.Shell"
    $ws.popup($myinput,3,'TK Installer',64)|SET-CLIPBOARD} 

SET-CLIPBOARD to offload the popup response code. Need to find a better output or a way to prevent printing this response.


function install-myapps(){
Clear-Host
#Variable to hold the application list
$myapps = (
'Microsoft.PowerShell',
'Microsoft-Windows.Terminal',
'Microsoft.DotNet.SDK.3_1',
'Microsoft.DotNet.SDK.5',
'Microsoft.DotNet.SDK.6',
'Microsoft.MSIXCore',
'Microsoft.msmpisdk',
'Microsoft.ADKPEAddon',
'Microsoft.WebDeploy',
'9N5LW3JBCXKF',
'Nlitesoft.NTLite',
'Libretro.RetroArch',
'Notepad++.Notepad++',
'CodecGuide.K-LiteCodecPack.Full',
'Foxit.FoxitReader',
'7zip.7zip',
'OBSProject.OBSStudio',
'XnSoft.XnConvert',
'XnView.Classic',
'XnSoft.XnViewMP',
'corel.winzip',
'XP8K0J757HHRDW')
#Parser
ForEach-Object($aa in $myapps.Split(',')){
#Notification
GW "Installing  $aa`nPlease wait..."
#Installer
WinGet install $aa --silent --accept-package-agreements --accept-source-agreements --force}
}

This code works perfectly in both command line and exe format; the latter using PS2EXE or IExpress. I just cannot figure out how to instantiate it post-setup from the unattended Win1021H2 side. Any help or insight would be greatly appreciated!


Solution

  • I was unable to figure out the process for this so I worked it around differently. Below is how I fixed this situation:

        # The first section opens and names function and 
        # declares variable $Hopeful applied to the full URI for the application we are installing
            # !Considering using get-input but for now we will just use a replaceable variable!
        # The second section begins the downloading and saving process 
            # Begins by separating the application from the URI assuming the format is as www.domain.com/application.exe
            # Note now that the variable $JustApp will pull the just the last portion of the URI which is the application name
            # Also, we'll make sure that what we're trying to do is possible by checking the extension of the last object
            # Because wget needs 2 things; the URI and a place for the download to go; I am creating a directory to put these
            # downloads in. Thus, $MyDir\$JustApp is now the default file point.
    cls
    Clear-Host
    
    $MyDir = "d:\TKDI\"
        # Create directory
           if($mydir|Test-Path){
           "My Directory Already Exists!"
           }else{
           md $MyDir -Force
           }
    # Section 1
            Function TKDI($Hopeful,$MyArgs){
            $_|select
    # Section 2            
        $JustApp = $hopeful -split('/')|select -last 1
    
        
      
        if($justapp -match "exe")
         { 
            switch($MyArgs)
            {
            inno{$x ='/sp- /silent /forcecloseapplications /restartapplications /norestart'}
            S{$x ='/S'}
            silent{$x ='/silent'}
            quiet{$x ='/quiet'}
            passive{$x ='-passive'}
            default{$x =$myargs}
            un{$x ='-uninstall'}
            $null{$x='/?'}
            }
            cls
            echo "Processing $justapp"
            if(Test-Path $mydir$justapp -PathType Leaf){echo 'File Downloaded Already!'}else{wget -Uri $hopeful -OutFile $MyDir$justapp}
            $noteit = 'Installing  $justapp in 5 seconds...'
            $x=6;while($x-- -ge 1){cls;Write-host  $x;sleep 1}
            start -verb runas -wait -FilePath $mydir$justapp -ArgumentList $x
    
           }elseif($justapp -match "msi") 
           {
           cls
            echo "You're file will be downloaded and installed!"
            wget -Uri $hopeful -OutFile $MyDir$justapp
            start -wait -Verb runas msiexec.exe -ArgumentList "-i $mydir$justapp /passive /norestart"
                }else{
            
              echo "This URI does not result in an application!"
        
             
         }
    
           }
    
    tkdi www.example.com/index.exe inno #Installs beautifully```