Advertisement

最近の PowerShell について

Jan. 22, 2022
Advertisement

More Related Content

Slideshows for you(20)

Similar to 最近の PowerShell について(20)

Advertisement

Recently uploaded(20)

Advertisement

最近の PowerShell について

  1. 最近の PowerShell について SCUGJ (wSCUGJ) 勉強会 #27 / 2022-01-22 Kazuki Takai - Windows Server & Cloud User Group Japan
  2. 本日お話しすること • PowerShell 7.2 と近辺で実装された機能について お話しします • 割と細かいです • 最近の PowerShell について何となく知っていた だければと思います
  3. PowerShell Community Dashboard
  4. PowerShell 7.2 Released • 7.2 GA – 2021-11-09 JST • 7.2.1 – 2021-12-15 JST • 7.3.0-preview.1 – 2021-12-17 JST • Long Term Support (LTS) Release • 3年間のサポート • 偶数マイナーバージョンは LTS として3年間サポート • 奇数マイナーバージョンは1年間サポート • .NET 6 ベース
  5. サポートライフサイクルと OS 要件 • PowerShell のサポート ライフサイクル
  6. PowerShell がサポートする OS の条件 • サポート対象となる条件 1. EoS になっていない OS バージョンである 2. OS のバージョンが、暫定リリース等ではない 3. 少なくとも1年以上サポートされている OS バージョ ンである 4. OS のバージョンと CPU アーキテクチャが、.NET (.NET Core)でサポートされている 5. PowerShell Team でテスト済みの組み合わせである
  7. PowerShell 7.2 の新機能・変更点 • Microsoft Update サポート • Linux 用の新しいユニバーサルパッケージ • PSReadLine 2.1 と予測 IntelliSense • DSC モジュールを PowerShell 本体から分離 • 試験的な機能から正式な機能へ変更されたもの • その他
  8. Microsoft Update サポート • Microsoft Update 経由で PowerShell の アップデートが可能となった • インストール時の既定値は、 有効(オプトインする) • 設定でオプトアウト可能 • WSUS による配信も可能 • コマンドラインオプション • USE_MU • ENABLE_MU
  9. Microsoft Update サポート • 注意点 • Windows 10 RS3 (10.0.16299) 以降が必要 • 新しいビルドがリリースされてから Microsoft Update で公開されるまで、2週間程度必要 • PowerShell としてセキュリティ更新を含んでいる場合 も、Optional の更新として配信
  10. Linux 用の新しいユニバーサルパッケージ • RPM と Deb パッケージが OS やバージョンに依 存せず(それぞれ)1つになった
  11. PSReadLine 2.1 と予測 IntelliSense • PSReadLine 2.1 を標準バンドル • CommandPrediction API を導入 • コマンドライン補完の予測を提供 • ユーザーの履歴から予測を行い、候補を提示可能 • 既定では無効 • Set-PSReadLineOption -PredictionSource History
  12. DSC モジュールを PowerShell 本体から分離 • PowerShell Engine から DSC の機能を分離して 個別のモジュールとして提供 • 開発サイクルを分離し、組み合わせの自由度を提供 • PSDesiredStateConfiguration • Version 2 が PowerShell 7.0 に同梱されていたもの • PowerShell 7.0 との互換性を確保する場合は Version 2 系のモジュールをインストール • Install-Module -Name PSDesiredStateConfiguration -Repository PSGallery -MaximumVersion 2.99
  13. PowerShell 7.2 の新機能・変更点 • 試験的な機能から正式な機能へ変更 • PSAnsiRendering • PSAnsiProgress • PSImportPSDataFileSkipLimitCheck • PSManageBreakpointsInRunspace • PSCultureInvariantReplaceOperator • PSNotApplyErrorActionToStderr • PSUnixFileStat • 試験的な機能として実装されていたが削除 • PSImplicitRemotingBatching
  14. PowerShell 7.2 の新機能・変更点 • 新しく追加された試験的な機能 • PSNativeCommandArgumentPassing • ネイティブ実行可能ファイルを呼び出すときの動作を変更 • 文字列を再構築するのではなく、StartProcessInfo オブジェクトの ArgumentList プロパティを使用 • PSAnsiRenderingFileInfo • $PSStyle.FileInfo に組み込みのメンバーを追加 • $PSStyle.FileInfo.Directory , $PSStyle.FileInfo.SymbolicLink 等 • PSLoadAssemblyFromNativeCode • ネイティブ コードからのアセンブリの読み込みを許可
  15. 試験的な機能 • Microsoft Docs 参照 • PowerShell の 試験的機能の使用
  16. PSNullConditionalOperators • Null 条件付きメンバーアクセス演算子(?. / ?[]) • 変数(アクセス対象)が Null ではない場合のみ、メン バーにアクセスし値を返す • アクセス対象が Null の場合は、メンバーへのアクセス は行わず $null を返す • PowerShell 7.1 から正式な機能として利用可能 • 使うなら #Requires -Version 7.1 しましょう • 省略せずにきちんと値のチェックをすることをお勧め します
  17. PSAnsiRendering • ターミナル出力のレンダリングにおいて、ANSI エス ケープシーケンスをサポート • xterm 互換のターミナルで利用可能 • Windows の場合は Console Host か Windows Terminal • macOS の場合は、OS デフォルトのターミナルアプリ • Linux の場合は、ディストリビューション次第
  18. PSAnsiRendering • $PSStyle.OutputRendering で動作を指定 ANSI (default) エスケープシーケンスが有効(既定) PlainText エスケープシーケンスを常に除外 Host リダイレクト又はパイプライン出力で エスケープシーケンスを除外
  19. PSAnsiRendering • 色の指定 • $PSStyle.Background と $PSStyle.Foreground • 組み込みの色名、又は FromRgb() による指定 • Black, BrightBlack, White, BrightWhite, Red, BrightRed, Magenta, BrightMagenta, Blue, BrightBlue, Cyan, BrightCyan, Green, BrightGreen, Yellow, BrightYellow
  20. PSAnsiRendering • スタイルの調整 • $PSStyle.Blink : 点滅オン • $PSStyle.Bold : 太字オン • $PSStyle.Hidden : 非表示オン • $PSStyle.Reverse : 逆順オン • $PSStyle.Italic : 斜体オン • $PSStyle.Underline : 下線オン • $PSStyle.****Off : ****をオフ • $PSStyle.Reset : すべてオフ
  21. PSAnsiRendering • 特定の書式の調整 • $PSStyle.Formatting • FormatAccent, TableHeader, ErrorAccent, Error, Warning, Verbose, Debug • $PSStyle.FileInfo (試験的な機能) • Directory, SymbolicLink, Executable, Extension • Enable-ExperimentalFeature -Name PSAnsiRenderingFileInfo -Scope CurrentUser
  22. PSAnsiProgress • プログレスバーの表示形式変更 • デフォルトは1行で出力される形式に変更 • $PSStyle.Progress で制御 • $PSStyle.Progress.View = ‘Minimal’ • $PSStyle.Progress.View = ‘Classic’ #以前の形式
  23. PSImportPSDataFileSkipLimitCheck • Microsoft.PowerShell.Utility.PSImportPSDataFil eSkipLimitCheck • Import-PowerShellDataFile の読み込み上限を無視 • -SkipLimitCheck を付与することで、制限を超えて ロード可能 • デフォルトは500個(500 key-value pair)までロード可能
  24. PSManageBreakpointsInRunspace • Microsoft.PowerShell.Utility.PSManageBreakpoi ntsInRunspace • Debug-Runspace 及び Debug-Job で BreakAll パラ メーターを使用可能 • *-PSBreakpoint コマンドレットで Runspace パラ メーターを使用可能
  25. PSCultureInvariantReplaceOperator • -replace 演算子の暗黙的な文字列変換時 • 言語設定(Culture)に依存した変換が行われていた問 題を修正(Culture に依存しない変換が行われる) • [string] への明示的なキャストと同じ挙動となる • 例 • フランス語言語環境において 1.2 –replace “,” が “12” にならなくなる
  26. PSNotApplyErrorActionToStderr • ネイティブコマンドが標準エラー出力に何か出力 した際、$Error に書き込まれなくなった • その結果、$ErrorActionPreference の影響もうけない
  27. PSUnixFileStat • Unix の stat API のデータを含めることで、Unix に似たファイルの一覧を提供(macOS & Linux)
  28. PSImplicitRemotingBatching (削除) • リモートセッション上のモジュールをインポート して、あたかもローカルコマンドのようにリモー トコマンドを実行する場合 • パイプラインのすべてのコマンドがリモート処理 プロキシコマンドである場合、パイプライン全体 をリモートで実行して、最終結果のみを転送 • PowerShell 7.2 で削除済み
  29. PowerShell 7.2 の新機能・変更点 • その他の破壊的な変更 • スクリプト コマンドレットからの全ての出力に対して - PipelineVariable が設定されるように改善 • ConvertTo-Json が -Depth の値を超えた場合、警告を出力 • 今までは暗黙的にデータロストしていた • -Directory スイッチのエイリアス D を削除 • システムのロックダウンが構成されている場合、 NoLanguage 及び RestrictedLanguage モードで New- Object を禁止(無効化) • 実行ポリシーバイパス構成の前に AppLocker 拒否構成を適用 • FileSystemInfo.Target を CodeProperty から FileSystemInfo.LinkTarget を指す AliasProperty に変更
  30. Demo
  31. PowerShell Crescendo • ネイティブコマンドに対する PowerShell ラッ パーを生成 • Install-Module Microsoft.PowerShell.Crescendo • Export-CrescendoModule -ConfigurationFile <config>.json -ModuleName <OutputModule>.psm1
  32. SecretManagement • 対応するキーストアの増加(モジュール増加) > Find-Module SecretManagement* | ft Name Name ---- SecretManagement.KeePass SecretManagement.JustinGrote.CredMan SecretManagement.Hashicorp.Vault.KV SecretManagement.LastPass SecretManagement.BitWarden SecretManagement.1Password SecretManagement.CyberArk SecretManagement.KeyChain Name ---- SecretManagement.Chromium SecretManagement.Keybase SecretManagement.PleasantPasswordServer SecretManagement.Keeper SecretManagement.DevolutionsHub SecretManagementArgumentCompleter SecretManagement.DevolutionsServer
  33. 余談:Windows PS5.1 と PS7 • 結構違う • $env:PSModulePath • 対応モジュール • PSRemoting (Transport Protocol) • 慣れていない場合は、使い分けた方が良い • 基本的に、モジュールが公式にサポートする方を使う
  34. まとめ • PowerShell 7.2 は細かい改善・変更が多い • うまく併用しつつ、バグがあればフィードバックを • モジュールの互換性に関する問題含め
  35. 参考資料 • PowerShell GitHub • PowerShell Developer Blog • Microsoft Docs – PowerShell • PowerShell Open Source Community Dashboard
Advertisement