「PowerShell」修訂間的差異
跳至導覽
跳至搜尋
(→FAQ) |
(→FAQ) |
||
行 74: | 行 74: | ||
Echo $item.Name | Echo $item.Name | ||
} | } | ||
+ | </source> | ||
+ | ===關閉程式與執行程式=== | ||
+ | *出處: [https://ithelp.ithome.com.tw/questions/10190951 PowerShell 偵測執行程式,並重啟 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天] | ||
+ | ;關閉程式 | ||
+ | <source lang="powershell"> | ||
+ | #取得授權 | ||
+ | Set-ExecutionPolicy RemoteSigned | ||
+ | |||
+ | #判斷與停止Client | ||
+ | if(Get-Process client -ErrorAction SilentlyContinue) | ||
+ | { | ||
+ | Stop-Process -Name client | ||
+ | } | ||
+ | |||
+ | #等待1s | ||
+ | Start-Sleep -s 1 | ||
+ | </source> | ||
+ | |||
+ | ;執行程式 | ||
+ | <source lang="powershell"> | ||
+ | #取得授權 | ||
+ | Set-ExecutionPolicy RemoteSigned | ||
+ | #執行項目 | ||
+ | [System.Diagnostics.Process]::Start("C:\Client\client.exe", "") | ||
</source> | </source> | ||
於 2019年12月3日 (二) 16:08 的修訂
PowerShell
- 安裝
- KB968930 - Windows Management Framework Core package (Windows PowerShell 2.0 and WinRM 2.0)
- KB968929 - Windows Management Framework (Windows PowerShell 2.0, WinRM 2.0, and BITS 4.0)
- 啟動方法
- 【開始】→【執行】→【powershell】
技術文件
常用指令
- Get-Help
- 取得指令的使用說明
- exit
- 離開PowerShell
- HELP
- 線上說明
- kill
- 停止執行中的程序
- ps
- 顯示執行中的程序狀態
相關套件
應用
- 如何使用 Windows PowerShell 以便在應用程式終止時收到通知?
- How Can I Use Windows PowerShell to Delete All the Files in a Folder Older Than 90 Days?
- 檢查檔案是否存在?如不存在則發email通知
- Download files from websites programatically via powershell
C#
FAQ
改善PowerShell的效能
取得網路卡資訊
Get-WmiObject win32_NetworkAdapter | %{ if ($_.PhysicalAdapter -and $_.Name -notmatch "Virtual") {$_ } }
使用7z
- Windows 腳本語言選擇
- Windows powershell還是可以使用7Z
- 重新命名資料夾名稱
- 使用xml檔
使用git
使用xml
取得資料夾內附檔名為zip的檔名
$Dir="D:/Folder" foreach($item in (dir $Dir "*.zip")){ Echo $item.Name }
關閉程式與執行程式
- 關閉程式
#取得授權 Set-ExecutionPolicy RemoteSigned #判斷與停止Client if(Get-Process client -ErrorAction SilentlyContinue) { Stop-Process -Name client } #等待1s Start-Sleep -s 1
- 執行程式
#取得授權 Set-ExecutionPolicy RemoteSigned #執行項目 [System.Diagnostics.Process]::Start("C:\Client\client.exe", "")
相關
- PowerShell 中文博客 - 收集和分享PowerShell相关教程,技术和最新动态