社内SEの話

日々起きたことの記録用

Powershell

【PowerShell】Excel列挙型が呼び出せない

PowerShell7で実行すると、Excelの罫線が引けない、理由は列挙型の挙動が変わっていました。原因と対処方法を解説しています。

【PowerShell】Excel チートシート

テンプレート $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $excel.DisplayAlerts = $true $book = $excel.Workbooks.Open(ファイルパス) $sheet = $book.Sheets(1) $r = 1 $c = 1 $sheet.cells.item($r,$c).value() ="Hello E…

【PowerShell】配列の値をランダムに入れ替える

Code 7.0以前 説明 Get-Random -Maximum -Minimum 別の例 Code 7.1以降 終わりに あまり発生する事例はありませんが、他言語であったのでPowerShellで実装してみました。 PowerShellのバージョンによってコマンドが違うので、実際のバージョンを確認してくだ…

PowerShell - Randomly swap array values

Before Code 7.0 Get-Random -Maximum -Minimum The Another example From Code 7.1 Finally, There are not many cases that occur, but since it was in another language, I tried implementing it with PowerShell. The command differs depending on th…

【Powershell】フォルダ内のファイル存在確認

Commands use case 存在確認にTest-Path関数を使用します。 ファイルのコピー、移動をさせる時に実際にファイルが無いとエラーになってしまいます。 コマンド実行前にファイルの存在確認した後にコマンド実行すると意図した動作が可能になります。 learn.mic…

【Powershell】Check existence of files in folder

Use Test-Path function for existence check. An error will occur if the file does not actually exist when copying or moving the file. If you execute the command after confirming the existence of the file before executing the command, the in…

【Powershell】ファイル名を置換して一括リネーム

Program サンプル 説明 1)Get-ChildItem:ファイル取得 2)Rename-Item -NewName :指定の文字を置換します ログなどの大量のファイルで特定の規則のファイル名を一括してリネームしたい時があります。 一つずつリネームするのは手間なのでPowershell を使っ…

Batch rename by replacing file names

Program sample Description 1) Get-ChildItem: 2)Rename-Item -NewName : Replace the specified characters There are times when you want to batch rename files with a specific rule in a large number of files such as logs. Renaming one by one is…

【Powershell】ファイル名を連番にリネーム

Powershellでファイル名を連番でリネームする方法を解説しています

[Powershell] Rename the file name to a serial number

Program Step1 Step2 Description Recently, there are many opportunities to handle a large amount of photos and process OCR. Even if it is in the acquired state, it is difficult to debug without renaming. You can rename it with Python etc., …

【Powershell】 フォルダ内のファイルサイズ大きい順に取得

ある日Cドライブの空き容量が逼迫してしまいました。 このPCにしてからファイル整理をしてこなかったので当然ですが、さすがにCドライブの逼迫はWindowsUpdateにも影響するのでファイル整理をして空き容量を増やします。 とはいえどのファイルを消せば効率よ…

【Powershell 】月初、月末を求める

Powershellで月末月初を求める書き方を解説しました。

【PowerShell】ビット全探索

Overview 与えられた値の全パターンを使って処理するプログラムの用事がありました。 競技プログラミングでビット全探索という単語を知りました。 競技ではPythonでしたが、実務でPowershellを使う場面が出てきたのでPythonからPowershellに置き換えたプログ…

タスクスケジューラでPowershellが実行できない時の勘所

こんにちは、はじめまして。めじろです。 Powershellで作ったスクリプトをタスクスケジューラで実行するケースは比較的多いです。 ただスケジューラを設定しても動かない、動いていないなんて事もよくあります。 タスクスケジューラからPowershellを実行する…

Powershell イベントログ書き込み

こんにちは、はじめまして。めじろです。 PowerShellでバッチ処理などのスクリプト処理をさせていると度々実行結果をログ出力したくなります。 テキストに書き出してもいいのですがイベントビューアーから見た方がちゃんとしたシステムっぽい動きになります…

PowerShellで使えるループ処理大全

こんにちは、はじめまして。めじろです。 PowerShellで使えるループ処理について日々使っていてナレッジがある程度溜まったので、メモとしてまとめてみました。 大半は docs.microsoft.com ここに書かれている通りですが、それ以外にも例外的な動きや、この…

Windows11でPowershellが起動しない場合

新しくWindows11を買ったのでこれまで同様にPowershellを使いながら、キッティング作業します。 ところが作業冒頭にPowershellが起動しないトラブルが発生したのでメモとして残します。 もし助けになればと思います。 'wt.exe'が見つかりません。名前を正し…