2020年7月11日 星期六

C# WebRequest 連接 https 發生 SSL 錯誤

這個問題在 .Net 4.5 以前無法自動切換至 SSL, 問題在於憑證的驗證, 網路上有許多做法, 不過現在最簡單的方法, 就是改成 .Net 4.6以上的版本就可以了,  預設使用 TLS1.2, 如果網站 TLS 版本不符, 用 ServicePointManager 指定版本就好

https://docs.microsoft.com/zh-tw/dotnet/framework/network-programming/tls

2020年7月8日 星期三

設定Windows排程器執行powershell script




在Windows排程器中編輯動作:

程式或指令碼: powershell
新增引數: -ExecutionPolicy Bypass -File "C:\RmtRuntime\rmt_zip_daily.ps1"




這裡必須指定 -ExecutionPolicy Bypass 才可執行

以下為 rmt_zip_daily.ps1 的內容
--------------------------------------------
#REQUIRES -Version 2

$ZipDate = [DateTime]::Today.AddDays(-1).ToString("yyyy-MM-dd")

$SourceFile = "D:\TempRMT\Source2020\$ZipDate.zip"
if (Test-Path $SourceFile) {
  Remove-Item $SourceFile
}
7z a $SourceFile  "E:\RMT Processing\Source\$ZipDate"
copy $SourceFile  "\\NAS01\Temp\Backup\Google\RMT Processing\Source2020\$ZipDate.zip"



$Source20sFile = "D:\TempRMT\Source2020-20s\$ZipDate.zip"
if (Test-Path $Source20sFile) {
  Remove-Item $Source20sFile
}
7z a $Source20sFile "E:\RMT Processing\Source20s\$ZipDate"
copy $Source20sFile "\\NAS01\Temp\Backup\Google\RMT Processing\Source2020-20s\$ZipDate.zip"