0. 前置き
PoorShell 5 (Windows に標準搭載) には偏執的なコマンドや環境があります。
Microsoft が Linux や GNU に憧れるのは理解できますが、改造が不十分なために意味不明な挙動を起こします。
(PoorShell 7 は Alias が 5 と異なるので、違う理由で混乱)
本稿は、Linux で慣れ親しんだ curl コマンドを普通に使うための設定を記述します。
動作環境:Windows11 Pro 24H2
1. 紛らわしいコマンドを探す
実行目的の Alias を列挙する。
この中で紛らわしいのは curl と wget で、curl.exe は存在するが wget.exe は存在しない。
なので curl を正常化する。
− □ × >_ Windows PowerShell × + | ∨
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows PS C:\> # 実行の Alias を探す PS C:\> Get-Alias | Where-Object { $_.Definition -match "^(Invoke|Get|Set)-" } ⏎ CommandType Name Version Source ----------- ---- ------- ------ Alias cat -> Get-Content Alias cd -> Set-Location Alias chdir -> Set-Location Alias curl -> Invoke-WebRequest Alias dir -> Get-ChildItem … 多いので省略 … Alias wget -> Invoke-WebRequest
PS C:\> # 実行ファイルが存在することを確認する PS C:\> Test-Path Alias:curl ⏎ True PS C:\> Get-Command curl.exe ⏎ CommandType Name Version Source ----------- ---- ------- ------ Application curl.exe 8.16.0.0 C:\WINDOWS\system32\ curl.exe
PS C:\> # 実行ファイルが存在しないことを確認する PS C:\> Test-Path Alias:wget ⏎ False PS C:\> Get-Command wget.exe ⏎ get-command : 用語 'wget.exe' は、コマンドレット、関数、スクリプト ファイル、または操作可 能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含 まれている場合はそのパスが正しいことを確認してから、再試行してください。 発生場所 行:1 文字:1 + get-command wget.exe + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (wget.exe:String) [Get-Command], CommandNotF oundException + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCo mmandCommand PS C:\> exit ⏎
2. Alias の無効化と有効化
curl に対する Alias の付け外しをしてみる。
一時的な対処であり、PoorShell を再起動すると効果が無くなる。
(確認が不要で時間の無駄と分かっている方は省略するのが吉)
− □ × >_ Windows PowerShell × + | ∨
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows PS C:\> # curl の Alias を外す PS C:\> Remove-Item Alias:curl ⏎ PS C:\> Test-Path Alias:curl ⏎ False
PS C:\> # curl の Alias を再作成 PS C:\> Set-Alias curl Invoke-WebRequest ⏎ PS C:\> Test-Path Alias:curl ⏎ True PS C:\> Get-Alias curl ⏎ CommandType Name Version Source ----------- ---- ------- ------ Alias curl -> Invoke-WebRequest PS C:\> exit ⏎
3. Alias の無効化を固定
PoorShell のプロファイルの参照位置確認と編集を実施する。
⇓
− □ × >_ Windows PowerShell × + | ∨
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows PS C:\> # プロファイルの参照位置を確認する PS C:\> $PROFILE ⏎ C:\Users\who\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\> # プロファイルのフォルダを作成する (既存でもエラーにならない) PS C:\> New-Item -ItemType Directory -Path (Split-Path $PROFILE) -Force ⏎ ディレクトリ: C:\Users\who\Documents Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2025/11/12 22:17 WindowsPowerShell PS C:\> # プロファイルのファイルをメモ帳で編集する (最初は存在しないので新規作成) PS C:\> notepad $PROFILE ⏎ PS C:\> exit ⏎
「メモ帳」で以下の 1 行をファイルに追加し、保存する。
if (Get-Alias curl -ErrorAction SilentlyContinue) { Remove-Item Alias:curl }
4. curl が普通になったことを確認
上記 3 で編集したプロファイルは PoorShell の起動時に適用される。
再起動せずに適用する場合は . $PROFILE を実行する。
*1 Invoke-WebRequest も証明書を無視できるが、標準ポート以外を指定すると使えない。
− □ × >_ Windows PowerShell × + | ∨
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows PS C:\> # curl の Alias がないことを確認する (1) PS C:\> Test-Path Alias:curl ⏎ False PS C:\> # curl の Alias がないことを確認する (2) PS C:\> Get-Alias curl ⏎ Get-Alias : name 'curl' を含むエイリアスは存在しないため、このコマンドは一致するエイリア スを見つけられません。 発生場所 行:1 文字:1 + Get-Alias curl + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (curl:String) [Get-Alias], ItemNotFoundExce ption + FullyQualifiedErrorId : ItemNotFoundException,Microsoft.PowerShell.Commands.GetAlia sCommand
PS C:\> # curl が普通であることを確認する PS C:\> curl -V ⏎ curl 8.16.0 (Windows) libcurl/8.16.0 Schannel zlib/1.3.1 WinIDN Release-Date: 2025-09-10 Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps m qtt pop3 pop3s smb smbs smtp smtps telnet tftp ws wss Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets PS C:\> # curl -k (証明書を無視して接続) も使えるようになった*1 PS C:\> curl --help all | Select-String -CaseSensitive " -k" ⏎ -k, --insecure Allow insecure server connections PS C:\> exit ⏎