2021-07-29

Auto Renew Let's Encrypt Certificate for SoftEther

After build up the SoftEther VPN https://youtu.be/Y1F4PJOsWF8


You can manually Import the Certificate


Or try to make it automatically.

Place Cert in C:\Cert\ and write a TXT file (C:\Cert\SoftEtherVPNCertBatch.txt) with the following command:

2021-07-08

WFH (Work From Home) 的情況下如何 Reset Computer Account Password

這個應該是用不到啦,畢竟就已經跟網域脫離關係,應該是用 Cache Credential 來登入作業系統
所以應該不會遇到 Computer Account Password 說過期,失去網路信任關係的問題

但如果有需要的話,VPN 先連上,然後下 PowerShell 指令

Test-ComputerSecureChannel -server DC.Contoso.com -credential Contoso\Adminstrator -repair

WFH (Work From Home) 的情況下重新登入網域取得帳號 Member Of 資訊的辦法 (重新登入作業系統)

User 在家工作一段時間
遇到密碼過期或因為需要取得帳號 Member Of 屬性
而需要在已經連接網域網路的情況下重新登入作業系統

先以 Local Account 登入作業系統
以 Windows 內建的 VPN,或 SoftEther VPN 也可以,連接好之後
敲 Command: tsdiscon 切換帳號 (Switch User)
這時 VPN 連線會持續存在,但可以換 AD Domain User Account 登入了
此時就能變更密碼、取得最新的 Momber Of 資訊及 GPO 等

2021-06-26

User Scrcpy to Connect to Android Devices over WiFi by PowerShell

只需要開啟 Android 的 USB 偵錯模式
再透過 Scrcpy 就能讓你在 PC 上連接 Android 裝置並顯示、操作
甚至可以透過無線網路來連接 (adb 內建功能)
以下為快速連接的 PowerShell Script
只要先指定好 adb.exe 及 scrcpy.exe 的 Path 就可以運作
達到快速連接的目的


$ADBPath = 'C:\scrcpy\adb.exe';
$ScrcpyPath = 'C:\scrcpy\scrcpy.exe';

$ConnectedDevices = @();
$ConnectionPrompt = '';
$ConnectionTargetIndex = 0;
$Reconnect = 'y';

2021-06-22

Export All Teams Channels Owners, Members and Guests with JSON format by PowerShell

Connect To Teams 的段落搭配
https://blog.dino9021.com/2020/11/connect-azaccount-with-saved-encryped.html

$ShowID = $True;

##### Get Self-Path #####
if (($MyInvocation.MyCommand).Path -ne $Null) {
$SelfPath = (($MyInvocation.MyCommand).Path -replace ($MyInvocation.MyCommand),' ');
} else {
$SelfPath = ((Get-Location).Path + '\');
};
##### Get Self-Path #####

#$webclient=New-Object System.Net.WebClient
#$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#[Net.ServicePointManager]::SecurityProtocol = "tls12"
#Install-Module MicrosoftTeams

2021-06-06

Shrink Azure VM OS Disk 縮小 Azure 上 VM 的 OS Disk 大小

 Azure 上面起一個 Windows VM 的 OS Disk 預設是 127GB

但通常用不到那麼大卻要負擔那麼多的租金
在以下網址找到可以縮小 OS Disk 的 PowerShell Script

https://github.com/jrudlin/Azure/blob/master/General/Shrink-AzDisk.ps1

需要注意 Script 的預設情況 Disk 是 沒有設置 Available Zone 
以下 Script 已經將 Disk 的 Available Zone 加入避免錯誤

2021-06-05

Windows Server 2019 NPS RADIUS 驗證失敗的問題

Windows Server 2019 的 NPS 有 RADIUS Server 服務設定
但即使完成了正確的設定,RADIUS Client 仍然無法正確取得驗證
如果此時將 Firewall 關閉則可以正確驗證
顯然問題出在防火牆上

解決辦法下一行 PowerShell 指令即可

Get-NetFirewallRule -DisplayGroup "Network Policy Server" | where DisplayName -like "*RADIUS*" | Set-NetFirewallRule -Service Any

Reference: https://social.technet.microsoft.com/Forums/en-US/0bf054af-eebe-4a2b-a07b-ccab174b234f/server-2019-radius-blocked-by-defender-firewall

2021-06-01

PowerShell 取得兩個字串中間的字串 Get SubString Between 2 Strings

$String = 'SString1T<String2>';

$Find = [Regex]::Matches($String, "(?<=S).+?(?=T)");
for($i = 0; $i -lt $Find.Count; $i++) {
    $Find[$i].Value;
};

$Find = [Regex]::Matches($String, "(?<=\<).+?(?=\>)");
for($i = 0; $i -lt $Find.Count; $i++) {
    $Find[$i].Value;
};

PowerShell Invoke-WebRequest 出現錯誤: The server committed a protocol violation. Section=ResponseStatusLine

又踩到雷啦!

用 PowerShell Invoke-WebRequest 向某個網站發出 Request 的時候出現錯誤:

The server committed a protocol violation. Section=ResponseStatusLine


解決辦法:

在 Invoke-WebRequest 之前先執行以下 Script: