0
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?

More than 3 years have passed since last update.

PowerShellでフォルダの中身のスクリーンショットを取得したい

Last updated at Posted at 2022-11-13

エビデンスでフォルダの中身のキャプチャをうん百枚と取る必要があるので作りました。

目次

リンク 説明
フォルダ構成 フォルダの構成。batファイルについてはこちら
実際のコード 前半部分はここを見てね
取得結果 取得するとこんな感じになるよ

フォルダ構成

フォルダ構成はこんな感じ
image.png
target.txtにキャプチャ取得したいディレクトリが入ってる。
image.png

実際のコード

日時・ログファイル定義 ~ スクリプト開始 の詳細は↓のページを見てね
PowerShellのスクリプトテンプレート

#キャプチャ取得 から画面キャプチャ処理をしてるよ

hoge.ps1
#実行前にディスプレイの比率を100%にすること。
#※倍率が高いとスクリーンショット取得時に画面が見切れてしまうことがある。

#==============日時・ログファイル定義==============
$Date = Get-Date -Format yyyy_MM_dd
$Time = Get-Date -Format HH_mm_ss
$Now = $Date + "_" + $Time
$Name_ps1 = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
$Log_Ps1 = "$PSScriptRoot\log\" + "$Name_ps1" + "_" + "$Now" + "_" + "$env:COMPUTERNAME" + "_"  + "$env:USERNAME" + ".log"

#==============スクリプト終了定義==============
Function Finish_Ps1{
    Write-Host (Get-Date -Format HH_mm_ss) "`t**********スクリプトを終了します**********"
    Stop-Transcript
    Exit
}

#==============スクリプト開始==============
Start-Transcript $Log_Ps1
Write-Host (Get-Date -Format HH_mm_ss) "`t**********スクリプトを開始します**********"
Write-Host ""

#==============キャプチャ取得==============
Write-Host (Get-Date -Format HH_mm_ss) "`t▼▼▼▼▼▼▼▼▼▼ScreenShot取得処理を開始します▼▼▼▼▼▼▼▼▼▼"
$Array_dir = Get-Content "$PSScriptRoot\target.txt"

foreach($i in $Array_dir){
    $i | ii
    Start-Sleep 2

    #画面定義
    [void][reflection.assembly]::loadwithpartialname("system.windows.forms")
    $MyScreenshot = [System.Windows.Forms.SystemInformation]::VirtualScreen
    $WID = $MyScreenshot.Width
    $HEI = $MyScreenshot.Height
    $LEFT = $MyScreenshot.Left
    $TOP = $MyScreenshot.Top

    #オブジェクト作成し、コピーする
    $MyBitmap = New-Object System.Drawing.Bitmap $WID, $HEI
    $MyDrawing = [System.Drawing.Graphics]::FromImage($MyBitmap)
    $MyDrawing.CopyFromScreen($LEFT, $TOP, 0, 0, $MyBitmap.Size)

    #bmpファイルを保存
    $MyFile = "$PSScriptRoot\log\" + (Get-Date -Format HH_mm_ss) + ".bmp"
    $MyBitmap.Save($MyFile)
}

Write-Host (Get-Date -Format HH_mm_ss) "`t▲▲▲▲▲▲▲▲▲▲ScreenShot取得処理を終了します▲▲▲▲▲▲▲▲▲▲"
Write-Host ""

#==============スクリプト終了==============
Finish_Ps1

取得結果

こんな感じでbmpファイルがlogフォルダにポコポコと取得される
image.png
中身はこんな感じ
image.png

参考にしたサイト

0
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
0
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?