Linux あれこれ

Linux 関連(一部 Windows11 )の備忘録です。

「Windows11」(22H2) にて、「PowerShell」のスクリプトの作成に「VSCode」を使う〈H165-3〉

登録日: 2023-04-02 更新日: 2023-04-02

こちらの「Linux あれこれ」は「Linux」メインで投稿してますが、「Windows11」で「Linux」を使う機能に興味があり、投稿しました。

-

前回 は、「Windows11」(22H2) の標準シェルである「Windows PowerShell 5.1」の機能強化版の「PowerShell 7」をインストールしました。

PowerShell 7」でシェルスクリプトを開発(デバッグ)するときは、「VSCode」とその拡張機能が使われるようなので、その環境をインストールしてみました。

その備忘録です。

-

-

使用したPC は、USB 3.0 ポートのある「Windows 11」のノートPC です。メモリ 12GB、SSD 1TB に増設しています。 「UEFI 立ち上げ」のPC です。

-

(注)リンクを戻るときはブラウザの左上の「←」をクリック

-

-


目次

-

前回の作業:

「Windows11」(22H2) と「Ubuntu」で、「PowerShell」を使う〈H165-2〉

-

今回の作業:

1. 「VSCode」をインストール:

2. 「PowerShell 拡張機能」をインストール:

3. 「VSCode」の使い方を学ぶ:

4. 「PowerShell」について学ぶ:

-

参考:

1. 「PowerShell」のコマンドレット:

2. 「ls」(Get-ChildItem) コマンドのヘルプ:

3. 「PowerShell」の Tips(役立つコツ):

-

「まとめ へ」

「目次詳細 へ」

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - -

「Windows11」(22H2) を起動:

-

立ち上げた「Windows11」の画面:

「Windows10」から「Windows11」にアップグレードしたので、デスクトップに以前使っていたアプリのアイコン(ショートカット)と「壁紙」が残っています。

-

PowerShell」から「VSCode」を起動 :

→この画面では、テキストファイルの作成に使っていますが、「PowerShell」の機能拡張をインストールすることで、「PowerShell」のスクリプトファイル (.ps1) の作成や実行してのデバッグに使えます。

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - --

1.「Windows PowerShell 5.1」について:

-

1). 「Windows11」(22H2) の「Windows ターミナル」で動く、基本の「シェル」です。

→「Windows PowerShell 5.1」は「Windows」に標準でプリインストールされており、「Windows」のみで使えます。

その後継の「PowerShell 7」は、機能強化だけでなく、マルチプラットフォーム版として他のOS にも提供されています。

-

2). コマンドで起動:

powershell.exe

→「.exe」は付けなくても起動できます。

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - ---

2.「PowerShell 7」について:

-

1).「PowerShell 7」は、「Windows PowerShell 5.1」を機能強化したマルチプラットフォーム版です。

-

2).「Windows PowerShell 5.1」と共存できます。

インストール場所も、アイコンも違います:

青い端末アイコン: 「Windows PowerShell 5.1」

黒い端末アイコン: 「PowerShell 7」

-

3). 使うにはインストールが必要です。

-

(1). 「PowerShell 7」のインストール:

こちら 」を参照:

-

インストール後は、モジュールが認識されていないので、再起動します

-

(2). 「PowerShell 7」のバージョンアップ:

こちら 」を参照:

-

(3). ヘルプファイルのダウンロードと更新:

こちら 」を参照:

-

(4). 起動したら、起動アイコンを右クリックして「タスクバーにピン留め」しておくと便利です。

-

4). 「PowerShell 7」をコマンドで起動:

PS C:\Users\user> pwsh
:
PowerShell 7.3.3

→起動時にバージョンが表示されます。

-

5). 起動して、バージョンを確認:

PS C:\Users\user> pwsh -version
PowerShell 7.3.3

-

もしくは、

PS C:\Users\user> $PSVersionTable.PSVersion
Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      3      3

→コマンドの補完機能を使うと入力が楽です。

「$PSV」Tab →「$PSVersionTable」

$PSVersionTable「.psv」Tab →「$PSVersionTable.PSVersion」Enter

-

6).「PowerShell 7」の終了:

PS C:\Users\user> exit

もしくは、「タブ」を閉じます。

-

7).「Windows」で、「PowerShell」の「シェルスクリプト」を使う場合:

こちら 」を参照:

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - ----

3.「Windows11」にて、「VSCode」をインストール:

-

参考:

Windows で Visual Studio Code を実行する

-

1). インストール:

-

(1). Windows 向けの「Visual Studio Code インストーラー」をダウンロード:

Visual Studio Code installer for Windows

→今回は、「VSCodeUserSetup-x64-1.76.2.exe」

-

(2). ダウンロードした「ファイル」をダブルクリック

-

(3). 「セットアップ」画面が表示:

-

(4). 「同意する」にチェック

→「次へ」

-

(5). インストール先:
C:\Users\user\AppData\Local\Programs\Microsoft VS Code

→「次へ」

-

(6). スタートメニューフォルダ:
Visual Studio Code

→「次へ」

-

(7). 追加タスクの選択:

そのまま

→「次へ」

→「インストール」

-

(8). 「インストール」開始

-

(9). 「インストール完了」画面:

Visual Studio Code を実行する」にチェックが入っています。

→「完了」をクリック

-

Visual Studio Code を実行する」のチェックを外して、すぐに「Windows11」を再起動する方がスムーズかも。

-

2). 「VS Code」が起動されました:

「Welcome」タブが表示:

→英語で表示

-

起動したときに、画面の右下に「表示言語を日本語に変更するには言語パッケージをインストールします。」の表示があれば、クリックするだけで「日本語化」できますが、

→今回は表示されないので、再起動しました。

-

3). 「Windows11」を再起動:

-

再起動することで、インストールで設定された %PATH% 環境変数の変更が有効になります。

-

4). 「VS Code」を起動:

PS C:\Users\user> code

-

5). 「Welcome」タブの表示:

画面の右下に「表示言語を日本語に変更するには言語パッケージをインストールします。」が表示:

→「インストールして再起動」をクリック

-

6). アプリが再起動され、日本語化されました:

「Welcome」タブが、「ようこそ」の表示に変更されました:

-

7). 日本語化されたことで、「ようこそ」タブの表示がわかりやすくなりました:

「ようこそ」タブでは、初期設定のガイドが表示されます:

→すべて設定しなくても良いので、日本語化後に、必要なものだけ、設定すれば良いと思います。

設定した項目には、設定済の青いチェックが付きます。

-

8). 試しに、 「好きな外観を選択します」をクリック:

-

(1). 選ぶ「テーマ」が決まっている場合:

右にある一覧から、

→「ダーク」をクリックして選択(デフォルト)

→「色のテーマを参照」をクリック

-

上段に一覧が表示:

Dark+ (default Dark)→「Monokai」に変更:

-

(2). 選ぶ「テーマ」が決まっていない場合:

「ようこそ」タブからの設定だと、テーマがどういう見た目なのかわかりません。

設定したいときは、「プログラム ファイル」や「Markdown ファイル」を開いておいて、変更します。

-

左側にある「エクスプローラ」アイコンをクリック:

→「フォルダを開く」をクリック:

-

「フォルダ」と「ファイル」を指定:

→任意: DOC\2023-03-02-memo.md

-

この画面で、「Ctrl+K」「Ctrl+T」を押して、「テーマの選択」一覧を表示:

-

「↓」「↑」キーで、テーマを変えると、テーマが「リアルタイム」に反映されます:

→好みのテーマを見つけたら、Enter で確定

-

9). 参考:

-

(1). デフォルトで、「VS Code」は下記のフォルダにインストールされます:
C:\Users\「ユーザ名」\AppData\Local\Programs\Microsoft VS Code\

→フォルダ名にスペースが含まれていることに注目

-

Microsoft VS Code」フォルダにある、ファイル名だけを(オブジェクトから選択して)表示:
PS C:\Users\user> Get-ChildItem 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\' | Select-Object Name

もしくは、

PS C:\Users\user> ls 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\' -Name
Name
----
bin
locales
policies
resources
tools
chrome_100_percent.pak
chrome_200_percent.pak
Code.exe                           ←(注目)
Code.VisualElementsManifest.xml
d3dcompiler_47.dll
ffmpeg.dll
icudtl.dat
libEGL.dll
libGLESv2.dll
resources.pak
snapshot_blob.bin
unins000.dat
unins000.exe
unins000.msg
v8_context_snapshot.bin
vk_swiftshader.dll
vk_swiftshader_icd.json
vulkan-1.dll

-

(2). 「VS Code」は、Windows では、 「ユーザ レベル」のセットアップと「システム レベル」のセットアップの両方を提供しています。

-

(3). 「ユーザ レベル」のセットアップは、管理者権限がなくても出来ます:

インストールすると、ユーザごとの「Local AppData (LOCALAPPDATA)」フォルダに配置されます。

そのユーザのみで「VS Code」を利用できます。

-

(4). 「システム レベル」のセットアップは、管理者権限が必要です:

インストールにて、システムの「Program Files」フォルダに配置されます。

管理者権限でインストールすると、すべてのユーザで「VS Code」を利用できます。

-

確認:

今回は、システムレベルでは、インストールしていないので下記には存在しません:

PS C:\Users\user> ls 'C:\Program Files\' -Name
:
Apoint2K
Bonjour
Common Files
game
HP
Intel
Internet Explorer
LibreOffice
Microsoft Office
Microsoft Update Health Tools
ModifiableWindowsApps
Mozilla Firefox
Notepad++
PCHealthCheck
PowerShell                       ←(注目)
Realtek
rempl
ruxim
UNP
VideoLAN
Windows Defender
Windows Mail
Windows Media Player
Windows NT
Windows Photo Viewer
WindowsPowerShell                ←(注目)

→「PowerShell」も、こちらのフォルダに配置されています。

-

(5). 自動更新されます:

毎月、リリースがあり、新しいリリースが利用可能になると通知されます。 通知があったとき、最新の更新プログラムを受け入れるとインストールされます。

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - -----

4.「VSCode」に、「PowerShell 拡張機能」をインストール:

-

1). ターミナルにて、「VSCode」を起動:

PS C:\Users\user> code

-

2). 左の一番下の「拡張機能」アイコンをクリック:

→サイド バーに「拡張機能」ビューが開きます:

-

3). 上部の検索窓に「powershell」と入力:

→表示された一覧で、一番上のMicrosoft の「PowerShell」の拡張機能を選択

-

4). MicrosoftPowerShell 拡張機能の、 「インストール」ボタンをクリック

-

5). 「この拡張機能はグローバルに有効化されています、」と表示されれば、「拡張機能」を使った編集が可能になります。

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - ----- -

5.「VSCode」の使い方を学ぶ:

-

1). 「PowerShell」にて、「VSCode」を起動:

PS C:\Users\user> code

-


2). 「VS Code」についての動画:

参考:

-

MacOS での操作説明なので、Windows とは特殊キーが違います:

Command :     「Ctrl」キー

Option :       「Alt」キー

Command +「←」 : 「Home」キー

Command +「→」 : 「End」キー

-

例えば、ファイルの上書き保存は、

MacOS の場合: 「Command + S」

Windows の場合: 「Ctrl + S」

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - ----- --

6.「PowerShell」について学ぶ:

-


1). 最初に見ておくと良さそうな Web サイト:

参考:

-

→PoweShell のコマンドレットの出力は、文字列ではなく、(.Net 経由の)「配列」(データのかたまり)です。 その配列についての予備知識。

-


2). 「PowerShell」のデバッグのやり方:

参考:

-


3). 「PowerShell」のトレーニング を行う Microsoft の Web サイト:

本家の Web サイトなので情報は確実です。「リンク」をたどりながら学習して行くので、深く入りすぎたり、道が外れやすいので、何を学ぶのか、はじめに「概要」(学ぶべき項目)をメモしておくのが良さそう:

-

抜粋:

-

「開始 >」ボタンをクリック

「概要 v」があったら、クリックして確認:

知りたい項目の「リンク」から、学んで行く学習方法です。

各項目が広く説明されているので、項目によって急に深くなったり、別の道にそれたり、リンクを押す順番で表示が変わってしまうのが難点。(逆に予想外のことが学べたりします)

サインインすると、「+追加」ボタンで、個人のコレクションにその項目を登録できます。

効率的な学習をするには、レベルによって読み飛ばす?、慣れが必要。

逆に、自分が知っていること以外に、知らないことがないか見直すには良いかも。

-


4). 「PowerShell」についての動画:

動画なのでわかりやすいです。感謝!! :

-

参考:

→「▶すべて再生」をクリック

-

Part 1  概要・起動方法・コマンドレット

Part 2  コマンドレット・コマンド・文字列

Part 3  パイプライン

Part 4  スクリプト・実行ポリシー・コメントベースのヘルプ  ←(今回の投稿に該当する項目)

Part 5  条件文 if~else / 比較演算子 / switch

Part 6  繰り返し文 for / foreach / while / do / break

Part 7  関数 / Function

Part 8  配列 / Array

Part 9  連想配列 / Hash Tables

Part 10  演算子 / Operators

Part 11  エラー処理 / Error handling

Part 12  Class と Enum

Part 13  PSプロバイダ/PSドライブ/レジストリ/環境変数/変数と型

Part 14  モジュール / Module

-


5). 参考:「コマンドプロンプト」と「PowerShell」の出力の違いを確認:

違いがわかるように、

VS Code」のフォルダを「コマンドプロンプト」と「PowerShell」で確認してみました:

-

(1). 「VS Code」はデフォルトで、下記のフォルダにインストールされます:
C:\Users\「ユーザ名」\AppData\Local\Programs\Microsoft VS Code\

→指定するときは、「フォルダ名」にスペースが含まれていることに注目

-

(2). 「Microsoft VS Code」フォルダを確認:
PS C:\Users\user> ls 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\'

もしくは、

PS C:\Users\user> Get-ChildItem 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\'
    ディレクトリ: C:\Users\user\AppData\Local\Programs\Microsoft VS Code


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----     2023/03/21 火     11:53                bin
d-----     2023/03/21 火     11:53                locales
d-----     2023/03/21 火     11:53                policies
d-----     2023/03/21 火     11:53                resources
d-----     2023/03/21 火     11:53                tools
-a----     2023/03/14 火     17:56         128506 chrome_100_percent.pak
-a----     2023/03/14 火     17:56         179027 chrome_200_percent.pak
-a----     2023/03/14 火     18:26      141072312 Code.exe                           ←(注目)
-a----     2023/03/14 火     17:56            376 Code.VisualElementsManifest.xml
-a----     2023/03/14 火     18:23        4901280 d3dcompiler_47.dll
-a----     2023/03/14 火     18:23        2387392 ffmpeg.dll
-a----     2023/03/14 火     17:56       10397488 icudtl.dat
-a----     2023/03/14 火     18:25         481160 libEGL.dll
-a----     2023/03/14 火     18:23        7192512 libGLESv2.dll
-a----     2023/03/14 火     17:56        4933174 resources.pak
-a----     2023/03/14 火     17:56         407384 snapshot_blob.bin
-a----     2023/03/21 火     11:53         451053 unins000.dat
-a----     2023/03/21 火     11:44        2629016 unins000.exe
-a----     2023/03/21 火     11:53          13609 unins000.msg
-a----     2023/03/14 火     17:56         730800 v8_context_snapshot.bin
-a----     2023/03/14 火     18:23        4769728 vk_swiftshader.dll
-a----     2023/03/14 火     17:56            106 vk_swiftshader_icd.json
-a----     2023/03/14 火     18:23         885144 vulkan-1.dll

→コマンドの補完機能を使うと入力が楽です。

「get-ch」Tab →「Get-ChildItem」

-

→結果は、文字列ではなく、「配列」として出力されます。

「ls」や「dir」は、「Get-ChildItem」コマンドのエイリアス(別名)です。

「user」は「ユーザ名」で、任意です。

-

(3). ファイル名だけを(オブジェクトから選択して)表示:
PS C:\Users\user> Get-ChildItem 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\' | Select-Object Name

もしくは、

PS C:\Users\user> ls 'C:\Users\user\AppData\Local\Programs\Microsoft VS Code\' -Name
Name
----
bin
locales
policies
resources
tools
chrome_100_percent.pak
chrome_200_percent.pak
Code.exe                           ←(注目)
Code.VisualElementsManifest.xml
d3dcompiler_47.dll
ffmpeg.dll
icudtl.dat
libEGL.dll
libGLESv2.dll
resources.pak
snapshot_blob.bin
unins000.dat
unins000.exe
unins000.msg
v8_context_snapshot.bin
vk_swiftshader.dll
vk_swiftshader_icd.json
vulkan-1.dll

→行頭のコマンド名の「Get-ChildItem」を別名で定義されている「ls」や「dir」に変えても結果は同じです。

-

(4). 参考: 「コマンドプロンプト」で確認すると:
C:\Users\user> dir C:\Users\user\AppData\Local\Programs\"Microsoft VS Code"\
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は 745A-4444 です

 C:\Users\user\AppData\Local\Programs\Microsoft VS Code のディレクトリ

2023/03/21 火  11:53    <DIR>          .
2023/03/21 火  11:53    <DIR>          ..
2023/03/21 火  11:53    <DIR>          bin
2023/03/14 火  17:56           128,506 chrome_100_percent.pak
2023/03/14 火  17:56           179,027 chrome_200_percent.pak
2023/03/14 火  18:26       141,072,312 Code.exe
2023/03/14 火  17:56               376 Code.VisualElementsManifest.xml
2023/03/14 火  18:23         4,901,280 d3dcompiler_47.dll
2023/03/14 火  18:23         2,387,392 ffmpeg.dll
2023/03/14 火  17:56        10,397,488 icudtl.dat
2023/03/14 火  18:25           481,160 libEGL.dll
2023/03/14 火  18:23         7,192,512 libGLESv2.dll
2023/03/21 火  11:53    <DIR>          locales
2023/03/21 火  11:53    <DIR>          policies
2023/03/21 火  11:53    <DIR>          resources
2023/03/14 火  17:56         4,933,174 resources.pak
2023/03/14 火  17:56           407,384 snapshot_blob.bin
2023/03/21 火  11:53    <DIR>          tools
2023/03/21 火  11:53           451,053 unins000.dat
2023/03/21 火  11:44         2,629,016 unins000.exe
2023/03/21 火  11:53            13,609 unins000.msg
2023/03/14 火  17:56           730,800 v8_context_snapshot.bin
2023/03/14 火  18:23         4,769,728 vk_swiftshader.dll
2023/03/14 火  17:56               106 vk_swiftshader_icd.json
2023/03/14 火  18:23           885,144 vulkan-1.dll
              18 個のファイル         181,560,067 バイト
               7 個のディレクトリ  111,034,871,808 バイトの空き領域

→こちらの出力は、「配列」(データのかたまり)ではなく「文字列」です。

ちなみに、シングルクォート「'文字列'」での文字列指定は使えませんでした。

-

(5). 参考: 「PowerShell」と同じ結果を得るには、「dir」コマンドの機能しだい:

ヘルプで機能を確認:

C:\Users\user> dir /?
ディレクトリ中のファイルとサブディレクトリを一覧表示します。

DIR [ドライブ:][パス][ファイル名] [/A[[:]属性]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]ソート順]] [/P] [/Q] [/R] [/S] [/T[[:]タイムフィールド]] [/W] [/X] [/4]

  [ドライブ:][パス][ファイル名]
              一覧表示するドライブ、ディレクトリ、またはファイルを指定します。

  /A          指定された属性のファイルを表示します。
  属性   D  ディレクトリ                R  読み取り専用
               H  隠しファイル               A  アーカイブ
               S  システム ファイル               I  非インデックス対象ファイル
               L  再解析ポイント             O  オフライン ファイル
               -  その属性以外
  /B          ファイル名のみを表示します (見出しや要約が付きません)。
  /C          ファイル サイズを桁区切り表示します。これは
              既定の設定です。/-C とすると桁区切りが表示されません。
  /D          /W と同じですが、ファイルを列で並べ替えた一覧を表示します。
  /L          小文字で表示します。
  /N          ファイル名を右端に表示する一覧形式を使用します。
  /O          ファイルを並べ替えて表示します。
  sortorder    N  名前順 (アルファベット)       S  サイズ順 (小さい方から)
               E  拡張子順 (アルファベット)   D  日時順 (古い方から)
               G  グループ (ディレクトリから)    -  降順
  /P          1 画面ごとに一時停止して表示します。
  /Q          ファイルの所有者を表示します。
  /R          ファイルの代替データ ストリームを表示します。
  /S          指定されたディレクトリおよびそのサブディレクトリのすべてのファイルを表示します。
  /T          どのタイム フィールドを表示するか、または並べ替えに使用するかを指定します。
  タイムフィールド   C  作成
              A  最終アクセス
              W  最終更新
  /W          ワイド一覧形式で表示します。
  /X          このオプションは 8dot3 形式以外のファイル名に対する短い名前を
              表示します。長い名前の前に短い名前を表示する点を除けば
              /N オプションと同じです。短い名前がない場合は、
              ブランクになります。
  /4          4 つの数字で年を表示します。

環境変数 DIRCMD にスイッチを設定できます。
/-W のように - (ハイフン) を付けると、そのスイッチは無効になります。

→「/」がオプション指定で使われおり、「-」 (ハイフン) は機能を無効にするスイッチです。

-

(6). 参考: ファイル名だけの表示なら、「/B」オプションが使えます:
C:\Users\user> dir C:\Users\user\AppData\Local\Programs\"Microsoft VS Code"\ /b
bin
chrome_100_percent.pak
chrome_200_percent.pak
Code.exe
Code.VisualElementsManifest.xml
d3dcompiler_47.dll
ffmpeg.dll
icudtl.dat
libEGL.dll
libGLESv2.dll
locales
policies
resources
resources.pak
snapshot_blob.bin
tools
unins000.dat
unins000.exe
unins000.msg
v8_context_snapshot.bin
vk_swiftshader.dll
vk_swiftshader_icd.json
vulkan-1.dll

→もし、使用するコマンドに欲しい機能がなければ、シェルの文字列操作を使うことになります。

シェルに文字列操作のコマンドが存在しないときは「外部アプリ」もしくは、テキストエディタの置換機能を利用します。

-

-


- --- - --- - --- - --- - --- - --- - --- - --- - ----- ---

7.「PowerShell」の Tips:

-


1).「PowerShell」を使うと役立つこと:

  • 作業の自動化:

  • 業務の効率化:

  • 他のOS にも流用しやすいスクリプトの作成:

-


2). はじめに、覚えておくべきコマンドレット

  • Get-Command →どんなコマンドがあるか調べられます

  • Get-Help   →コマンドの使い方を調べられます

  • Get-Member →出力されたオブジェクトについて調べられます

→「PowerShell」専用のコマンドを「コマンドレット」と言います。

-


3).「Get-Help」を初めて実行するときに、ヘルプ ファイルをインストールするか求められます:

それ以降は、「Update-Help」の実行でインストールされます。

Update-Help

言語(カルチャー)指定が必要なら、

Update-Help -UICulture en-US -Verbose

日本語が良いなら、

Update-Help -UICulture ja-JP -Verbose

多くのヘルプ ファイルがダウンロードされるため、「Update-Help」で読み込めるのは 1日に 1回だけです。強制的に上書きするには「-Force」フラグを付けます。

-


4). 「PowerShell」のスクリプトの複数行を 1行にまとめたり、複数行に分割するやり方:

参考:

-

複数の行をひとつの行にしたい時:
Write-Host "5秒後に開始" ;Start-Sleep -s 5

→接続したい行頭に「;」(セミコロン)を使います。

-

1行を分割したい時:
Get-ChildItem -Path C:\Users\user\AppData\Local\Programs\"Microsoft VS Code"\ `
 | Select-Object Name

→分割したい部分の行末に、「`」(バッククォート: Shift+@)を使います。

-

上記の貼り付けをターミナルで行うと、警告が表示されるので、

→「強制的に貼り付け」をクリックして、Enter

-


5).「PowerShell」のスクリプトであれば、キーボード操作やマウス操作が行えます:

GUI 操作ができると、おもしろいことができそう。

おもしろいと、勉強が長続きします:

-

参考:

-


6).「PowerShell」で使用できるコマンドを確認:

-

Windows PowerShell 5.1」の場合:
PS C:\Users\user> Get-Command -CommandType Cmdlet | Select-Object Name
Name
----
Add-AppProvisionedSharedPackageContainer
Add-AppSharedPackageContainer
Add-AppxPackage
Add-AppxProvisionedPackage
Add-AppxVolume
Add-BitsFile
Add-CertificateEnrollmentPolicyServer
Add-Computer
Add-Content
Add-History
Add-JobTrigger
Add-KdsRootKey
Add-LocalGroupMember
Add-Member
Add-PSSnapin
Add-Type
Add-WindowsCapability
Add-WindowsDriver
Add-WindowsImage
Add-WindowsPackage
Checkpoint-Computer
Clear-Content
Clear-EventLog
Clear-History
Clear-Item
Clear-ItemProperty
Clear-KdsCache
Clear-Recyclebin
Clear-Tpm
Clear-Variable
Clear-WindowsCorruptMountPoint
Compare-Object
Complete-BitsTransfer
Complete-DtcDiagnosticTransaction
Complete-Transaction
Confirm-SecureBootUEFI
Connect-PSSession
Connect-WSMan
ConvertFrom-Csv
ConvertFrom-Json
ConvertFrom-SecureString
ConvertFrom-String
ConvertFrom-StringData
Convert-Path
Convert-String
ConvertTo-Csv
ConvertTo-Html
ConvertTo-Json
ConvertTo-ProcessMitigationPolicy
ConvertTo-SecureString
ConvertTo-TpmOwnerAuth
ConvertTo-Xml
Copy-BcdEntry
Copy-Item
Copy-ItemProperty
Copy-UserInternationalSettingsToSystem
Debug-Job
Debug-Process
Debug-Runspace
Disable-AppBackgroundTaskDiagnosticLog
Disable-BcdElementBootDebug
Disable-BcdElementBootEms
Disable-BcdElementDebug
Disable-BcdElementEms
Disable-BcdElementEventLogging
Disable-BcdElementHypervisorDebug
Disable-ComputerRestore
Disable-JobTrigger
Disable-LocalUser
Disable-PSBreakpoint
Disable-PSRemoting
Disable-PSSessionConfiguration
Disable-RunspaceDebug
Disable-ScheduledJob
Disable-TlsCipherSuite
Disable-TlsEccCurve
Disable-TlsSessionTicketKey
Disable-TpmAutoProvisioning
Disable-WindowsErrorReporting
Disable-WindowsOptionalFeature
Disable-WSManCredSSP
Disconnect-PSSession
Disconnect-WSMan
Dismount-AppxVolume
Dismount-WindowsImage
Enable-AppBackgroundTaskDiagnosticLog
Enable-BcdElementBootDebug
Enable-BcdElementBootEms
Enable-BcdElementDebug
Enable-BcdElementEms
Enable-BcdElementEventLogging
Enable-BcdElementHypervisorDebug
Enable-ComputerRestore
Enable-JobTrigger
Enable-LocalUser
Enable-PSBreakpoint
Enable-PSRemoting
Enable-PSSessionConfiguration
Enable-RunspaceDebug
Enable-ScheduledJob
Enable-TlsCipherSuite
Enable-TlsEccCurve
Enable-TlsSessionTicketKey
Enable-TpmAutoProvisioning
Enable-WindowsErrorReporting
Enable-WindowsOptionalFeature
Enable-WSManCredSSP
Enter-PSHostProcess
Enter-PSSession
Exit-PSHostProcess
Exit-PSSession
Expand-WindowsCustomDataImage
Expand-WindowsImage
Export-Alias
Export-BcdStore
Export-BinaryMiLog
Export-Certificate
Export-Clixml
Export-Console
Export-Counter
Export-Csv
Export-FormatData
Export-ModuleMember
Export-PfxCertificate
Export-ProvisioningPackage
Export-PSSession
Export-StartLayout
Export-StartLayoutEdgeAssets
Export-TlsSessionTicketKey
Export-Trace
Export-WindowsCapabilitySource
Export-WindowsDriver
Export-WindowsImage
Find-LapsADExtendedRights
Find-Package
Find-PackageProvider
ForEach-Object
Format-Custom
Format-List
Format-SecureBootUEFI
Format-Table
Format-Wide
Get-Acl
Get-Alias
Get-AppProvisionedSharedPackageContainer
Get-AppSharedPackageContainer
Get-AppxDefaultVolume
Get-AppxPackage
Get-AppxPackageAutoUpdateSettings
Get-AppxPackageManifest
Get-AppxProvisionedPackage
Get-AppxVolume
Get-AuthenticodeSignature
Get-BcdEntry
Get-BcdEntryDebugSettings
Get-BcdEntryHypervisorSettings
Get-BcdStore
Get-BitsTransfer
Get-Certificate
Get-CertificateAutoEnrollmentPolicy
Get-CertificateEnrollmentPolicyServer
Get-CertificateNotificationTask
Get-ChildItem
Get-CimAssociatedInstance
Get-CimClass
Get-CimInstance
Get-CimSession
Get-Clipboard
Get-CmsMessage
Get-Command
Get-ComputerInfo
Get-ComputerRestorePoint
Get-Content
Get-ControlPanelItem
Get-Counter
Get-Credential
Get-Culture
Get-DAPolicyChange
Get-Date
Get-DeliveryOptimizationLog
Get-DeliveryOptimizationLogAnalysis
Get-Event
Get-EventLog
Get-EventSubscriber
Get-ExecutionPolicy
Get-FormatData
Get-Help
Get-History
Get-Host
Get-HotFix
Get-InstalledLanguage
Get-Item
Get-ItemProperty
Get-ItemPropertyValue
Get-Job
Get-JobTrigger
Get-KdsConfiguration
Get-KdsRootKey
Get-LapsADPassword
Get-LapsDiagnostics
Get-LocalGroup
Get-LocalGroupMember
Get-LocalUser
Get-Location
Get-Member
Get-Module
Get-NonRemovableAppsPolicy
Get-Package
Get-PackageProvider
Get-PackageSource
Get-PfxCertificate
Get-PfxData
Get-PmemDedicatedMemory
Get-PmemDisk
Get-PmemPhysicalDevice
Get-PmemUnusedRegion
Get-Process
Get-ProcessMitigation
Get-ProvisioningPackage
Get-PSBreakpoint
Get-PSCallStack
Get-PSDrive
Get-PSHostProcessInfo
Get-PSProvider
Get-PSReadLineKeyHandler
Get-PSReadLineOption
Get-PSSession
Get-PSSessionCapability
Get-PSSessionConfiguration
Get-PSSnapin
Get-Random
Get-Runspace
Get-RunspaceDebug
Get-ScheduledJob
Get-ScheduledJobOption
Get-SecureBootPolicy
Get-SecureBootUEFI
Get-Service
Get-SystemPreferredUILanguage
Get-TimeZone
Get-TlsCipherSuite
Get-TlsEccCurve
Get-Tpm
Get-TpmEndorsementKeyInfo
Get-TpmSupportedFeature
Get-TraceSource
Get-Transaction
Get-TroubleshootingPack
Get-TrustedProvisioningCertificate
Get-TypeData
Get-UICulture
Get-Unique
Get-Variable
Get-WheaMemoryPolicy
Get-WIMBootEntry
Get-WinAcceptLanguageFromLanguageListOptOut
Get-WinCultureFromLanguageListOptOut
Get-WinDefaultInputMethodOverride
Get-WindowsCapability
Get-WindowsDeveloperLicense
Get-WindowsDriver
Get-WindowsEdition
Get-WindowsErrorReporting
Get-WindowsImage
Get-WindowsImageContent
Get-WindowsOptionalFeature
Get-WindowsPackage
Get-WindowsReservedStorageState
Get-WindowsSearchSetting
Get-WinEvent
Get-WinHomeLocation
Get-WinLanguageBarOption
Get-WinSystemLocale
Get-WinUILanguageOverride
Get-WinUserLanguageList
Get-WmiObject
Get-WSManCredSSP
Get-WSManInstance
Group-Object
Import-Alias
Import-BcdStore
Import-BinaryMiLog
Import-Certificate
Import-Clixml
Import-Counter
Import-Csv
Import-LocalizedData
Import-Module
Import-PackageProvider
Import-PfxCertificate
Import-PSSession
Import-StartLayout
Import-TpmOwnerAuth
Initialize-PmemPhysicalDevice
Initialize-Tpm
Install-Language
Install-Package
Install-PackageProvider
Install-ProvisioningPackage
Install-TrustedProvisioningCertificate
Invoke-CimMethod
Invoke-Command
Invoke-CommandInDesktopPackage
Invoke-DscResource
Invoke-Expression
Invoke-History
Invoke-Item
Invoke-LapsPolicyProcessing
Invoke-RestMethod
Invoke-TroubleshootingPack
Invoke-WebRequest
Invoke-WmiMethod
Invoke-WSManAction
Join-DtcDiagnosticResourceManager
Join-Path
Limit-EventLog
Measure-Command
Measure-Object
Mount-AppxVolume
Mount-WindowsImage
Move-AppxPackage
Move-Item
Move-ItemProperty
New-Alias
New-BcdEntry
New-BcdStore
New-CertificateNotificationTask
New-CimInstance
New-CimSession
New-CimSessionOption
New-DtcDiagnosticTransaction
New-Event
New-EventLog
New-FileCatalog
New-Item
New-ItemProperty
New-JobTrigger
New-LocalGroup
New-LocalUser
New-Module
New-ModuleManifest
New-NetIPsecAuthProposal
New-NetIPsecMainModeCryptoProposal
New-NetIPsecQuickModeCryptoProposal
New-Object
New-PmemDedicatedMemory
New-PmemDisk
New-ProvisioningRepro
New-PSDrive
New-PSRoleCapabilityFile
New-PSSession
New-PSSessionConfigurationFile
New-PSSessionOption
New-PSTransportOption
New-PSWorkflowExecutionOption
New-ScheduledJobOption
New-SelfSignedCertificate
New-Service
New-TimeSpan
New-TlsSessionTicketKey
New-Variable
New-WebServiceProxy
New-WindowsCustomImage
New-WindowsImage
New-WinEvent
New-WinUserLanguageList
New-WSManInstance
New-WSManSessionOption
Optimize-AppxProvisionedPackages
Optimize-WindowsImage
Out-Default
Out-File
Out-GridView
Out-Host
Out-Null
Out-Printer
Out-String
Pop-Location
Protect-CmsMessage
Publish-DscConfiguration
Push-Location
Read-Host
Receive-DtcDiagnosticTransaction
Receive-Job
Receive-PSSession
Register-ArgumentCompleter
Register-CimIndicationEvent
Register-EngineEvent
Register-ObjectEvent
Register-PackageSource
Register-PSSessionConfiguration
Register-ScheduledJob
Register-WmiEvent
Remove-AppProvisionedSharedPackageContainer
Remove-AppSharedPackageContainer
Remove-AppxPackage
Remove-AppxPackageAutoUpdateSettings
Remove-AppxProvisionedPackage
Remove-AppxVolume
Remove-BcdElement
Remove-BcdEntry
Remove-BitsTransfer
Remove-CertificateEnrollmentPolicyServer
Remove-CertificateNotificationTask
Remove-CimInstance
Remove-CimSession
Remove-Computer
Remove-Event
Remove-EventLog
Remove-Item
Remove-ItemProperty
Remove-Job
Remove-JobTrigger
Remove-LocalGroup
Remove-LocalGroupMember
Remove-LocalUser
Remove-Module
Remove-PmemDedicatedMemory
Remove-PmemDisk
Remove-PSBreakpoint
Remove-PSDrive
Remove-PSReadLineKeyHandler
Remove-PSSession
Remove-PSSnapin
Remove-TypeData
Remove-Variable
Remove-WindowsCapability
Remove-WindowsDriver
Remove-WindowsImage
Remove-WindowsPackage
Remove-WmiObject
Remove-WSManInstance
Rename-Computer
Rename-Item
Rename-ItemProperty
Rename-LocalGroup
Rename-LocalUser
Repair-WindowsImage
Reset-AppSharedPackageContainer
Reset-AppxPackage
Reset-ComputerMachinePassword
Reset-LapsPassword
Resolve-DnsName
Resolve-Path
Restart-Computer
Restart-Service
Restore-Computer
Resume-BitsTransfer
Resume-Job
Resume-ProvisioningSession
Resume-Service
Save-Help
Save-Package
Save-SoftwareInventory
Save-WindowsImage
Select-Object
Select-String
Select-Xml
Send-DtcDiagnosticTransaction
Send-MailMessage
Set-Acl
Set-Alias
Set-AppBackgroundTaskResourcePolicy
Set-AppxDefaultVolume
Set-AppxPackageAutoUpdateSettings
Set-AppXProvisionedDataFile
Set-AuthenticodeSignature
Set-BcdBootDefault
Set-BcdBootDisplayOrder
Set-BcdBootSequence
Set-BcdBootTimeout
Set-BcdBootToolsDisplayOrder
Set-BcdDebugSettings
Set-BcdElement
Set-BcdHypervisorSettings
Set-BitsTransfer
Set-CertificateAutoEnrollmentPolicy
Set-CimInstance
Set-Clipboard
Set-Content
Set-Culture
Set-Date
Set-DscLocalConfigurationManager
Set-ExecutionPolicy
Set-Item
Set-ItemProperty
Set-JobTrigger
Set-KdsConfiguration
Set-LapsADAuditing
Set-LapsADComputerSelfPermission
Set-LapsADPasswordExpirationTime
Set-LapsADReadPasswordPermission
Set-LapsADResetPasswordPermission
Set-LocalGroup
Set-LocalUser
Set-Location
Set-NonRemovableAppsPolicy
Set-PackageSource
Set-ProcessMitigation
Set-PSBreakpoint
Set-PSDebug
Set-PSReadLineKeyHandler
Set-PSReadLineOption
Set-PSSessionConfiguration
Set-ScheduledJob
Set-ScheduledJobOption
Set-SecureBootUEFI
Set-Service
Set-StrictMode
Set-SystemPreferredUILanguage
Set-TimeZone
Set-TpmOwnerAuth
Set-TraceSource
Set-Variable
Set-WheaMemoryPolicy
Set-WinAcceptLanguageFromLanguageListOptOut
Set-WinCultureFromLanguageListOptOut
Set-WinDefaultInputMethodOverride
Set-WindowsEdition
Set-WindowsProductKey
Set-WindowsReservedStorageState
Set-WindowsSearchSetting
Set-WinHomeLocation
Set-WinLanguageBarOption
Set-WinSystemLocale
Set-WinUILanguageOverride
Set-WinUserLanguageList
Set-WmiInstance
Set-WSManInstance
Set-WSManQuickConfig
Show-Command
Show-ControlPanelItem
Show-EventLog
Show-WindowsDeveloperLicenseRegistration
Sort-Object
Split-Path
Split-WindowsImage
Start-BitsTransfer
Start-DscConfiguration
Start-DtcDiagnosticResourceManager
Start-Job
Start-OSUninstall
Start-Process
Start-Service
Start-Sleep
Start-Transaction
Start-Transcript
Stop-Computer
Stop-DtcDiagnosticResourceManager
Stop-Job
Stop-Process
Stop-Service
Stop-Transcript
Suspend-BitsTransfer
Suspend-Job
Suspend-Service
Switch-Certificate
Tee-Object
Test-Certificate
Test-ComputerSecureChannel
Test-Connection
Test-DscConfiguration
Test-FileCatalog
Test-KdsRootKey
Test-ModuleManifest
Test-Path
Test-PSSessionConfigurationFile
Test-WSMan
Trace-Command
Unblock-File
Unblock-Tpm
Undo-DtcDiagnosticTransaction
Undo-Transaction
Uninstall-Language
Uninstall-Package
Uninstall-ProvisioningPackage
Uninstall-TrustedProvisioningCertificate
Unprotect-CmsMessage
Unregister-Event
Unregister-PackageSource
Unregister-PSSessionConfiguration
Unregister-ScheduledJob
Unregister-WindowsDeveloperLicense
Update-FormatData
Update-Help
Update-LapsADSchema
Update-List
Update-TypeData
Update-WIMBootEntry
Use-Transaction
Use-WindowsUnattend
Wait-Debugger
Wait-Event
Wait-Job
Wait-Process
Where-Object
Write-Debug
Write-Error
Write-EventLog
Write-Host
Write-Information
Write-Output
Write-Progress
Write-Verbose
Write-Warning

→コマンド名で、どのようなことを行うコマンドなのかが予想できます。それが「PowerShell」の利点です。

-

PowerShell 7.3.3」で変更されたコマンドレット:

差分表示:

-Add-PSSnapin
-Clear-Recyclebin
+Clear-RecycleBin               ←(名前の変更)
+Convert-Path
+ConvertFrom-Markdown
+ConvertFrom-SddlString
-ConvertFrom-String
-Convert-Path
-Convert-String
+Disable-ExperimentalFeature
+Enable-ExperimentalFeature
-Export-Console
+Format-Hex
+Get-Error
+Get-ExperimentalFeature
+Get-FileHash
-Get-LapsDiagnostics
+Get-MarkdownOption
-Get-PSSnapin
+Get-Uptime
+Get-Verb
+Import-PowerShellDataFile
+Join-String
+New-Guid
+New-TemporaryFile
+Remove-Alias
-Remove-PSSnapin
+Remove-Service
-Resume-Job
+Set-MarkdownOption
+Show-Markdown
+Start-ThreadJob
-Suspend-Job
+Test-Json

差分の表示について:

行頭が「-」は、「PowerShell 7.3.3」で削除されました。
行頭が「+」は、「PowerShell 7.3.3」で追加されました。

-

-


まとめ

「Windows11」で、「VSCode」をインストールして、拡張機能をインストールしました。

-

実際に使わないと身に付かないので、

わかりやすそうな教材がないか、Web を検索したり、簡単なシェルスクリプトを作ってみると良いと思います。

-

-

-


-

-

    目次

-

「投稿の先頭 へ」

-

-


-

「この目次 の先頭へ」

「本編の目次 に戻る」

-