投稿

ラベル(PowerShell)が付いた投稿を表示しています

PowerShellでEXCELのファイル比較してみた

 仕事で EXCEL のファイルを比較して差があればエラーにしてほしい。手段は問わないみたいな依頼があって、どうやってやろうかと思っていました。 EXCELマクロでやるしかないかなぁと思っていたら。 なんと PowerShell でも GUI 制御できそうって話があったので、 Gemini に任せて作成させてみました。(マクロでやるとトラストセンター設定とかややこしそうなので・・・) 必要な機能はあるけど、、、、遅すぎる。処理方法は少し考えた方がよいか どのシート参照するかとか細かな制御とか入れていないのでまだまだ不十分ですが、サンプル的に準備したものなので、まぁこの程度で十分ですが 役に立たなさそうだけどこちらに上げておきました。 ↓ https://github.com/Otazoman/fileComparisonTool なんか、速度改善できる方法ないかなぁ。 ◆参考サイト ・GUI作成 https://qiita.com/tkotobu1048/ items/fd009f1f321265634f68 ・EXCEL処理 https://qiita.com/23fumi/ items/aa65ffa2098509337d33 https://zenn.dev/y_a_y/ articles/ps_excel_ a0685efa3cc1ea https://www.ospn.jp/osc2018- kyoto/pdf/OSC2018_Kyoto_ Nakamura.pdf https://qiita.com/vicugna- pacos/items/ 54c5e20d3c3ffae94518 https://www.texcell.co.jp/ PowerShell/excel/psExcel.html https://yururi-do.com/excel- automation-by-powershell/ https://kamifuji.dyndns.org/ PS-Support/PS_Excel/index.html https://pg-note.com/archives/ 2311 https://zenn.dev/omu_tryangle/ articles/fbdc474e4f7142 https://blog.exeo- digit...

【PowerShell】Slackに日本語のコメント付きで投稿するPowerShell

 なんか月の作業でSlackに添付ファイル付けて投稿するとかいう定例の作業があるので面倒なので何とかできないかと思ってPowerShellを準備してみました。結構手こずりましたが何とか動きました。 SlackのAPI難しい・・・・。 ■PowerShell # Slack APIのトークンと投稿先チャンネルを設定 $slackToken = "xoxp-" $channel = "T" # チャンネルIDを適宜変更 $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path # テキストファイルから日本語メッセージをUTF-8エンコーディングで読み込む $filePath = Join-Path -Path $scriptPath -ChildPath "work\message.txt" $message = Get-Content -Path $filePath -Raw -Encoding UTF8 # 月と年を取得 $month = Get-Date -Format "MM" $year = Get-Date -Format "yyyy" # $monthを置換してコメントにセット $message = $message -replace '\$month', $month # Slack APIに送信するリクエストの組み立て $apiURL = "https://slack.com/api/files.upload" $headers = @{ "Authorization" = "Bearer $slackToken" } try { # 添付ファイルのパスを設定 (ここでは例として"yyyymm_capture.xlsx"を指定) $attachmentFileName = "work\{0}{1}_capture.xlsx" -f $year, $month $attachmentPath = Join-Path -Path $s...

PowerShellからS3に同期

うーん。 なんというか文字コードに悩まされた。 後はタスクスケジューラに仕込んで動くかどうかだが・・・・。 ちなみにそのままAWSのツールインストールすると文字化けするので PythonからAWSのCLIは入れなおしてます。 http://dev.classmethod.jp/cloud/aws/awscli-for-windows/ んで、PowerShellではまるとは・・・。 ISEだと文字化けしないけどPowerShellコンソールから 動かすと日本語ファイルがあると文字化けするんだよな~。 けどイベントビューアに出力するようにしたから start-transcript $logfileと日本語文字化けのとこはいいや・・・。 $frompath = "C:\Users\Administrator\Desktop\work" $tosite = "s3:S3バケット名" $logfile = "C:\work\Console.log" $pythonpPath = "C:\Python34\Scripts" $errKeyword = "Completed 1 part(s) with ... file(s) remaining" $worningKeyword = "Completed 0 part(s) with ... file(s) remaining" start-transcript $logfile cd $pythonpPath $result = .\aws s3 sync $frompath $tosite $result | Out-File $logfile -Append -Encoding utf8 stop-transcript #S3から返されたエラーに応じた処理 switch ($result){ $errKeyword{ $ErrMsg = "S3Syncでエラーが発生しました。バゲット接続エラー。"+ "`n" + $result Write-EventLog -LogName S3Sync...