首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何添加powershell脚本,以便在windows 10无人参与的安装过程中运行post安装?

如何添加powershell脚本,以便在windows 10无人参与的安装过程中运行post安装?
EN

Stack Overflow用户
提问于 2022-09-22 02:23:58
回答 1查看 156关注 0票数 0

我可能用错误/更困难的方法来做这件事。我愿意听取建议。

我正在运行NTLite v2.3.8.8920 HOME来创建无人值守的Windows 10光盘。在做了多年无人值守的光盘并实现了磁盘的不断扩展(最新的光盘是32.73GB!)之后,我找到了绝对令人惊叹的存储库WinGet,甚至创建了我自己的安装程序!

今天的问题是:如何在无人值守的安装过程中访问WinGet?我已经编制了一个我经常使用的应用程序列表;大多数应用程序是我一直在对磁盘进行硬编码的,因此它的大小令人难以置信;我希望能够在安装后运行这个脚本,并节省时间和空间。这是我的代码:

代码语言:javascript
复制
#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} 

设置剪贴板以卸载弹出响应代码。需要找到更好的输出或防止打印此响应的方法。

代码语言:javascript
复制
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}
}

这段代码在命令行和exe格式下都能很好地工作;后者使用PS2EXE或IExpress。我只是不知道如何从无人值守的Win1021H2端实例化它。任何帮助或洞察力都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-04 14:35:11

我无法弄清楚这个过程,所以我用不同的方法来处理它。以下是我如何解决这种情况的方法:

代码语言:javascript
复制
    # 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```
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73808692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档