xlogI125’s blog

パソコン作業を効率化したい

PowerShell

PowerShell練習 @([AutomationNull]::Value)

メモ 空の$nullについてメモ # PowerShell 5.1, Windows 11 Set-StrictMode -Version Latest $emptyNull = [System.Management.Automation.Internal.AutomationNull]::Value $null -eq $emptyNull #=> True @($emptyNull).Length #=> 0 @(, $emptyNull).Leng…

PowerShell練習 PDFのしおり名としおり移動先ページ番号をCSV形式でクリップボードにコピー

メモ PowerShellで [Interaction]::CreateObject と [Interaction]::CallByName の練習 参考資料リンク Interaction.CreateObject(String, String) Method (Microsoft.VisualBasic) | Microsoft Learn Interaction.CallByName(Object, String, CallType, Obj…

Get-ChildItem -File の BaseName, Extension をCSV形式でクリップボードにコピー

メモ Rename-Itemに使用する文字列の生成をExcelワークシートで行う場合を想定 参考資料リンク about PSCustomObject - PowerShell | Microsoft Learn https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.sort?view=netframew…

PowerShell練習 Excelワークシートでの並べ替え用に順序(StrCmpLogicalW)の連番を作成

メモ 範囲C1:C5をコピーする A B C 1 val11 値0005 =CLEAN(B1) 2 val21 値004 =CLEAN(B2) 3 val31 値02 =CLEAN(B3) 4 val41 値1 =CLEAN(B4) 5 val51 値3 =CLEAN(B5) 使い捨てスクリプトの実行結果を貼り付ける A B C 1 val11 値0005 5 2 val21 値004 4 3 val…

PowerShell練習 CSVファイルをStrCmpLogicalWの順で並べ替える 2

メモ csvファイルの読み込み [List[PSCustomObject]](Import-Csv -Encoding UTF8 -LiteralPath $args[0]) 並べ替え List.Sort(Comparer<PSObject>) 並べ替えに使用する列名は決め打ち 使い捨てスクリプト PowerShell.exeへのショートカット経由で実行 csvファイルの先</psobject>…

PowerShell練習 List.Sort(Comparer<PSObject>)

メモ List.Sort(Comparer<PSObject>) で並べ替え 参考資料リンク Get-Clipboard (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs 使い捨てスクリプト # PowerShell 5.1, Windows 11 # このスクリプトのファイル名 # "%USERPROFILE%\Desktop\test.ps1</psobject>…

PowerShell練習 CSVファイルをStrCmpLogicalWの順で並べ替える

メモ Import-Csv で取得した PSCustomObject の配列を List に変換 List.Sort(Comparer[PSCustomObject]) や List.Sort(Comparison<PSObject>) で PSCustomObject の NoteProperty の値を StrCmpLogicalW に渡して並べ替え 並べ替えに使用する列名は決め打ち CSVファイ</psobject>…

PowerShell練習 PSObject.Properties

メモ ConvertFrom-Csv で取得した配列を Add-Type で定義してあるC#に渡して PSObject.Properties の様子を見る。 参考資料リンク PSObject Class (System.Management.Automation) | Microsoft Docs 使い捨てスクリプト # PowerShell 5.1, Windows 11 Set-St…

PowerShell練習 .Sort([Delegate]::CreateDelegate([Comparison[T]], Type, "StrCmpLogicalW"))

メモ クリップボード内のテキストをStrCmpLogicalWの順で並べ替えたものをクリップボードにコピーする 参考資料リンク Everything you wanted to know about arrays - PowerShell | Microsoft Docs about Comparison Operators - PowerShell | Microsoft Docs…

PowerShell練習 パスに角括弧[]を含む作業フォルダー

パスに角括弧[]を含む場合、アドレスバーに powershell と入力してPowerShellを起動しても、起動時のカレントディレクトリが期待した場所になっていない様子。 # C:\tmp\■`$'([長すぎる対象のパス])'$`■ Set-Location -LiteralPath 'C:\tmp\■`$''([長すぎる…

PowerShell練習 フォルダのサイズを一覧で表示

メモ 1つのフォルダのサイズを表示 Get-ChildItem -LiteralPath .\ -Force -Recurse | Where-Object {$_.psobject.properties.match('Length').Count -ne 0} | Measure-Object -Property Length -Sum 参考資料リンク PSCustomObject Everything you wanted t…

PowerShell練習 Add-Type (StrCmpLogicalW) 3

メモ 現在のフォルダ内にあるファイル名を StrCmpLogicalW と List<T>.Sort(Comparison<T>) でソートして取得 参考資料リンク 型パラメーターの制約 - C# プログラミング ガイド | Microsoft Docs https://docs.microsoft.com/en-us/dotnet/api/system.collections</t></t>…

PowerShell練習 画像ファイルを作成

メモ テスト用に画像ファイルを作成する 使い捨てスクリプト # PowerShell 5.1, Windows 11 using assembly System.Drawing using namespace System.Drawing # 解像度 $dpi = 150 # A4横(ヨコ297mm×タテ210mm) $pxWidth = 297 / 25.4 * $dpi $pxHeight = 210…

PowerShell練習 [Graphics]::FromImage(Bitmap)

メモ jpegファイルの大きさ(ピクセル)を変更するための応急的な手段としてPowerShellで System.Drawing.Bitmap を使用する 取扱い可能なイメージの大きさ(ピクセル)、ビットの深さは気にしない 参考資料リンク about Using - PowerShell | Microsoft Docs Sy…

PowerShell練習 Add-Type (StrCmpLogicalW) 2

目次 目次 使い捨てスクリプト 現在のフォルダ内にあるファイル名をソートして取得 クリップボード内のテキストをソート 過去記事 使い捨てスクリプト 現在のフォルダ内にあるファイル名をソートして取得 このスクリプトを起動させるショートカット(.lnk)をS…

Acrobat Standard で JavaScript デバッガー を開く

プロパティのアクション IAC VBA PowerShell %APPDATA%にあるフォルダに保存 参考資料リンク 過去記事 プロパティのアクション バージョンは Acrobat Standard DC (2022年2月頃)、Windows 11。 「JavaScriptを実行」で console.show(); を実行する しおりの…

Acrobat IAC練習 JavaScript デバッガー を開く

メモ JavaScript デバッガーを表示するのにショートカットキーや しおり を使用してはいけない場合、OLEでJSObjectを経由して console.show() を行う方法を考える。 参考資料リンク Creating .NET and COM Objects New Object - PowerShell | Microsoft Docs…

PowerShell練習 Add-Type (StrCmpLogicalW)

メモ 自然順ソートとして StrCmpLogicalW を DllImport して Add-Type で加える ソートは List.Sort メソッドかバブルソート 参考資料リンク StrCmpLogicalW function (shlwapi.h) - Win32 apps | Microsoft Docs Working with Strings - Win32 apps | Micro…

WshShortcut (PowerShell.exe -ExecutionPolicy RemoteSigned)

メモ ExecutionPolicy を RemoteSigned として PowerShell_ISE.exe を起動するだけのショートカットを作成するVBAとPowerShellスクリプト PowerShell_ISE.exe のパラメーターは気にしない 参考資料リンク WshShortcut Object | Microsoft Docs Creating .NET…

PowerShell練習 ファイル名から -match で連番の数字を取り出す

メモ ファイル名から -match で連番の数字を取り出す 参考資料リンク about Regular Expressions - PowerShell | Microsoft Docs Everything you wanted to know about variable substitution in strings - PowerShell | Microsoft Docs 使い捨てスクリプト …

PowerShell練習 既存のフォルダ名をコピーして新規にフォルダを作成

既存のフォルダ名をクリップボードにコピーする。 # PowerShell 5.1, Windows 10 (Get-ChildItem -Directory).Name | Set-Clipboard コピーしたフォルダ名を here-string として貼り付ける。 # PowerShell 5.1, Windows 10 $dirNames = @' 新しいフォルダー …

PowerShell練習 CSVの作成

メモ multidimensional array の内容を Add-Member で PSCustomObject に写して PSCustomObject の配列を ConvertTo-Csv に渡す 参考資料リンク about Arrays - PowerShell | Microsoft Docs Add-Member (Microsoft.PowerShell.Utility) - PowerShell | Micr…

PowerShell練習 .psobject.Properties.Name

メモ CSVの操作ではなく、PSCustomObjectの配列をどう扱うか 参考資料リンク Everything you wanted to know about PSCustomObject - PowerShell | Microsoft Docs 使い捨てスクリプト ConvertTo-Csv に続けて ConvertFrom-Csv を実行した後の内容を見る # P…

PowerShell練習 Call operator ・ VBA練習 CallByName

メモ Docs の Call operator & と CallByName function を参照してください。 参考資料リンク about Operators - PowerShell | Microsoft Docs CallByName function (Visual Basic for Applications) | Microsoft Docs 使い捨てスクリプト ショートカット(.l…

PowerShell練習 ScriptBlock

Docs の about_Script_Blocks を参照してください。 # PowerShell 5.1 # Windows 10 # このスクリプトをメモ帳で保存する際は、 # 文字コードを UTF-8(BOM付き) として保存してください。 Set-StrictMode -Version Latest $f0 = { param([double[]]$x) Write…

Excelでファイル名を変更したい 2

メモ 下記の動作を行うPowerShellスクリプトです。 Get-ChildItemのBaseName、Extension、NameプロパティをExcelシートに書き出す ExcelシートでRename-Itemの文字列を生成する セキュリティソフトによっては、日本語のファイル名を対象に多くのRename-Item…

Excelでファイル名を変更したい

大量のファイルに対して、ある程度の融通を利かせてリネームしたい場合に便利かもしれません。例えば新版PDFと旧版PDFのページを1つのPDFに交互に並び替えたい場合に役立つと思います。 ・PDF編集ソフトでPDFのページを分割 ・分割されたPDFのファイル名を調…