From: 011netservice@gmail.com Date: 2025-06-07 Subject: PowerShell.txt https://svc.011.idv.tw/CodeHelper/Windows/PowerShell.txt 歡迎來信交流, 訂購軟體需求. 指令繁雜, 本檔案只列出常用簡短指令. 太長的指令或應用, 則以外部檔案補充: https://svc.011.idv.tw/CodeHelper/Windows/CommandSamples/ #### PowerShell Command Reference, 20250607 #* Get-Help #* & "C:\path\to\openssl.exe" version | 執行指定路徑的 .exe #* $env:Path -split ';' | 查詢環境變數 Path 路徑清單. #* $env:Path -split ';' | Where-Object { $_ -match "openssl" } | 查詢環境變數 Path 中包含 openssl 的路徑. # cpcp | 主控台使用中的字碼頁. # chcp 65001 | 主控台切換字碼頁為UTF8. # chcp 950 | 主控台使用中的字碼頁. # [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | 主控台切換字碼頁為UTF8. # ExecutionPolicy Bypass -File .\腳本.ps1 | 暫時可執行這個腳本 #* Get-Command -Name openssl -All | Select-Object Source | 列出所有在系統路徑中可執行的 openssl.exe,顯示它們的實際位置。 #* Get-ChildItem -Path C:\ -Filter openssl.exe -Recurse -ErrorAction SilentlyContinue | 搜尋整個磁碟中名為 openssl.exe 的檔案 查詢防火牆 DisplayGroup="遠端桌面" # Get-NetFirewallRule -DisplayGroup "遠端桌面" | ForEach-Object { $rule = $_ $filter = Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $rule [PSCustomObject]@{ Name = $rule.Name DisplayName = $rule.DisplayName Enabled = $rule.Enabled Direction = $rule.Direction Action = $rule.Action Profile = $rule.Profile RemoteAddress = $filter.RemoteAddress } } 查詢防火牆 LocalPort in ("3389", "443", "80") # Get-NetFirewallRule | ForEach-Object { $rule = $_ $addressFilter = Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $rule $portFilter = Get-NetFirewallPortFilter -AssociatedNetFirewallRule $rule if ($portFilter.LocalPort -in @("3389", "443", "80")) { [PSCustomObject]@{ Name = $rule.Name DisplayName = $rule.DisplayName Enabled = $rule.Enabled Direction = $rule.Direction Action = $rule.Action Profile = $rule.Profile RemoteAddress = $addressFilter.RemoteAddress Protocol = $portFilter.Protocol LocalPort = $portFilter.LocalPort RemotePort = $portFilter.RemotePort } } } #* Get-ExecutionPolicy | 檢查執行目前可執行腳本原則. 預設為 Restricted. RemoteSigned:允許執行本機腳本,但從網路下載的腳本必須有有效的簽章。 AllSigned:所有腳本都必須有簽章。 Restricted:不允許執行任何腳本(預設值)。 # Set-ExecutionPolicy RemoteSigned | 允許執行本機建立的腳本,但從網路下載的腳本需要有有效的簽章。 # Set-ExecutionPolicy AllSigned | 所有腳本都必須有簽章。 #* Set-ExecutionPolicy Bypass -Scope Process | 目前 PowerShell 工作階段中可執行腳本, 會提示確認訊息. #* Set-ExecutionPolicy Bypass -Scope Process -Force | 目前 PowerShell 工作階段中可執行腳本, 不提示確認訊息, 直接套用設定.