V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
treblex
V2EX  ›  分享创造

分享一个 powershell 脚本,一键安装本地目录准备好的软件

  •  
  •   treblex ·
    lazyfury · 4 天前 · 612 次点击
    
    # 获取当前脚本所在的目录
    $scriptDirectory = $PSScriptRoot
    
    # 指定要扫描的目录(不包含子目录)
    $installDirectory = "$scriptDirectory\快速安装"  # 这里可以指定你的安装目录
    
    # 获取指定目录下的所有文件(不包含子目录)
    $filePaths = Get-ChildItem -Path $installDirectory -File
    
    # 手动添加额外的文件路径
    # $filePaths += "$scriptDirectory\快速安装\VisualStudioSetup.exe"
    # $filePaths += "$scriptDirectory\快速安装\Adobe_Photoshop_2023_24.3.0.376_ACR15.3_SP_20230418\Adobe Photoshop 2023 SP\Set-up.exe"
    
    function Install-SetupApp{
        param(
            [Parameter(Mandatory=$true)]
            [string]$filePath  # 接收一个文件路径数组
        )
    
        # return
    
        if ($filePath.EndsWith(".exe") -or $filePath.EndsWith(".msi")) {  # 只执行 .exe 或 .msi 文件
                # 检查文件是否存在
                if (Test-Path $filePath) {
                    Write-Host "正在安装: $($filePath)"
                    Start-Process -FilePath $filePath -Wait
                } else {
                    Write-Host "文件不存在: $($filePath)"
                }
            }
    
    }
    
    
    # 输出文件路径数组(调试用)
    # $filePaths
    
    foreach($filePath in $filePaths){
        if($filePath.Name.EndsWith(".exe") -or $filePath.Name.EndsWith("msi")){
            Install-SetupApp -filePath $installDirectory\$filePath
        }
    }
    
    Install-SetupApp -filePath "$installDirectory\Adobe_Photoshop_2023_24.3.0.376_ACR15.3_SP_20230418\Adobe Photoshop 2023 SP\Set-up.exe"
    
    Write-Host "所有文件安装完成"
    
    
    
    
    TrackBack
        1
    TrackBack  
       4 天前
    吾爱打过来了?这脚本随便一个 ai 都能写
    而且没有静默安装参数需要点点点的软件你怎么办
    treblex
        2
    treblex  
    OP
       4 天前
    @TrackBack 就是 gpt 辅助写的,我够用了
    treblex
        3
    treblex  
    OP
       4 天前
    @TrackBack 7zip 这种支持静默安装,其他的自定义安装器很难支持
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5908 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 01:55 · PVG 09:55 · LAX 18:55 · JFK 21:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.