2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【改訂】Wingetコマンドによるアプリ更新

Last updated at Posted at 2025-07-28

ご挨拶

1年ぶりに自分のコマンドを見てみると効率が悪いというか、耳がタコになるというか……
過去記事の書き直しです。

※2025年11月3日さらに短縮コードができたので追記編集

※追記コードは一番最後

過去記事  wingetコマンドによるブラウザやAdobe、Teamsアプリの更新

目次

※.注意
1.手順①batファイルの作成
2.手順②ps1ファイルの作成
3.手順③統合版ファイルの作成






注意!!

検証を重ねてコード掲載に至っておりますが、ご利用は最新の公式情報を参照の上、自己責任でお願い申し上げます。
また、ある程度コマンドプロンプトや、PowerShellを実行経験済みの方が参考にされる事をお勧めします。
一部手順を省略している場合があり、お使いのOS環境によりましては上手く動作しない場合がございます。

本記事は下記3点をご理解頂いている前提で書いております。
ご不安な方は過去記事  wingetコマンドによるブラウザやAdobe、Teamsアプリの更新 をお読みください。

わかる方はこのままレッツGO~♪

①「.bat」ファイルの作成方法

②「.ps1」ファイルの作成方法

③アップデートするアプリの探し方と注意点




手順①batファイルの作成


.batファイルのコード
@echo off
pushd %~dp0
:: 管理者実行のコード
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)

set /p answer="アプリ更新を実行しますか?(y/n):"

if "%answer%" == "y" (
  echo 実行します。


:: 「***」の部分は任意のファイル名にしてください。
powershell -Noprofile -ExecutionPolicy Unrestricted .\***.ps1
) else if "%answer%" == "n" (
  echo かしこまりました。実行を中止します。
)




手順②ps1ファイルの作成




.ps1ファイルのコード

# アップグレード対象のアプリ一覧
$apps = @(
    "Microsoft.Edge",
    "Google.Chrome",
    "Mozilla.Firefox",
    "Adobe.Acrobat.Reader.32-bit",
    "Microsoft.Teams"
)
 
foreach ($app in $apps) {
    winget list --id $app -e
    winget upgrade --id $app --force
}




手順③ ①と②の統合版

.batファイルのコード

<# : 
@echo off & setlocal EnableDelayedExpansion
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
set BATCH_ARGS=%*
for %%A in (!BATCH_ARGS!) do set "ARG=%%~A" & set "ARG=!ARG:'=''!" & set "PWSH_ARGS=!PWSH_ARGS! "'!ARG!'""
endlocal &  Powershell -NoProfile -Command "$input|&([ScriptBlock]::Create((gc '%~f0'|Out-String)))" %PWSH_ARGS%
exit/b
: #>

# ここから下にPowerShellスクリプトを書き込むとコマンドプロンプトでPowerShellを実行できるようになる。
# ----------------------------------------------------------------------------------
# ユーザーに確認
$answer = Read-Host "アプリ更新を行いますか? (y/n)"

switch ($answer.ToLower()) {
    "y" {

# アップグレード対象のアプリ一覧
$apps = @(
    "Microsoft.Edge",
    "Google.Chrome",
    "Mozilla.Firefox",
    "Adobe.Acrobat.Reader.32-bit",
    "Microsoft.Teams"
)

# foreachコマンドで1つずつ更新ファイルの確認とアップグレードを実行 
foreach ($app in $apps) {
    winget list --id $app -e
    winget upgrade --id $app --force

}
 }
    "n" {
        Write-Host "処理を終了します。" -ForegroundColor Yellow
        exit
    }
    Default {
        Write-Host "y または n を入力してください。" -ForegroundColor Red
    }
}

Read-Host "終了するにはEnterを押してください"

以上です。最後まで閲覧いただきありがとうございました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?