March 2025
Intermediate to advanced
1002 pages
14h 55m
Japanese
Content preview from PowerShellクックブック 第4版
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,







O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
第8章. ユーティリティ・タスク
この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com
8.0 はじめに
スクリプトを書くとき、あるいは単に対話式シェルを使うとき、コマンドの計測、乱数の取得など、単純だが便利なニーズがいくつか発生する。
8.1 システムの日付と時刻を取得する
問題
システムの日付を取得したい。
解決策
システムの日付を取得するには、コマンドGet-Date を実行する。
8.2 コマンドの持続時間を測定する
問題
コマンドの実行にかかる時間を知りたい。
解決策
コマンドの継続時間を測定するには、 コマンドレットを使用する:Measure-Command
PS > Measure-Command { Start-Sleep -Milliseconds 337 }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 339
Ticks : 3392297
TotalDays : 3.92626967592593E-06
TotalHours : 9.42304722222222E-05
TotalMinutes : 0.00565382833333333
TotalSeconds : 0.3392297
TotalMilliseconds : 339.2297
ディスカッション
インタラクティブな使用では、コマンドの実行時間を測定したい場合がよくある。例えば、開発したアプリケーションのパフォーマンス・ベンチマークを実行するような場合だ。Measure-Command コマンドレットは、これを簡単に行うことができる。このコマンドはリッチなオブジェクトベースの出力を生成するため、その出力を多くの日付関連タスクに使用することができる。詳細は、レシピ 3.8を参照のこと。
コマンド測定の精度が重要な場合、一般化されたシステムアクティビティは、結果のタイミングに影響を与えやすい。精度を向上させるための一般的なテクニックは、測定を何度も繰り返し、外れ値(上位10パー セントと下位10パーセント)を無視し、残りの結果を平均化することである。例8-1は、 このテクニックを実装している。
例 8-1. コマンドパフォーマンス測定.ps1
################################################################################## Measure-CommandPerformance#### From PowerShell Cookbook ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access