「PowerShell」修訂間的差異
跳至導覽
跳至搜尋
(→技術文件) |
|||
行 15: | 行 15: | ||
==技術文件== | ==技術文件== | ||
− | + | *[https://docs.microsoft.com/zh-tw/powershell/ PowerShell 文件 - PowerShell | Microsoft Docs] | |
− | *[ | ||
− | |||
*[http://search.microsoft.com/results.aspx?mkt=zh-TW&setlang=zh-TW&q=Windows+PowerShell 搜尋微軟網站上的『Windows PowerShell』] | *[http://search.microsoft.com/results.aspx?mkt=zh-TW&setlang=zh-TW&q=Windows+PowerShell 搜尋微軟網站上的『Windows PowerShell』] | ||
*[https://ithelp.ithome.com.tw/users/20005121/ironman/54 強而有力的 Windows PowerShell :: 2009 iT 邦幫忙鐵人賽] | *[https://ithelp.ithome.com.tw/users/20005121/ironman/54 強而有力的 Windows PowerShell :: 2009 iT 邦幫忙鐵人賽] | ||
<!-- | <!-- | ||
+ | *[http://www.microsoft.com/downloads/details.aspx?FamilyId=DF8ED469-9007-401C-85E7-46649A32D0E0&displaylang=en Windows PowerShell Quick Reference] | ||
+ | *[http://www.microsoft.com/taiwan/technet/columns/profwin/28-monad.mspx 易學易用的 Windows PowerShell] | ||
;Technet 專欄 | ;Technet 專欄 | ||
#[http://www.microsoft.com/taiwan/technet/columns/profwin/56-Winpowerwshell.mspx Windows PowerShell 講座 (1)—指令、重導、別名] | #[http://www.microsoft.com/taiwan/technet/columns/profwin/56-Winpowerwshell.mspx Windows PowerShell 講座 (1)—指令、重導、別名] | ||
行 28: | 行 28: | ||
#[http://www.microsoft.com/taiwan/technet/columns/profwin/67-Winpowerwshell5.mspx Windows PowerShell 講座 (5)—存資料的其他方式及編寫指令碼的前置準備] | #[http://www.microsoft.com/taiwan/technet/columns/profwin/67-Winpowerwshell5.mspx Windows PowerShell 講座 (5)—存資料的其他方式及編寫指令碼的前置準備] | ||
//--> | //--> | ||
+ | |||
==常用指令== | ==常用指令== | ||
*Get-Help | *Get-Help |
於 2020年5月25日 (一) 21:02 的修訂
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】
技術文件
- PowerShell 文件 - PowerShell | Microsoft Docs
- 搜尋微軟網站上的『Windows PowerShell』
- 強而有力的 Windows PowerShell :: 2009 iT 邦幫忙鐵人賽
常用指令
- 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", "")
除超過30天的資料庫備份檔
- 參考: 用PowerShell刪除N天前或指定日期(前後)建立(或修改)的檔案 | 程式前沿
- 檔案:ClearDbBackup.ps1
# 清除超過30天的資料庫備份檔 # # 用法: # 用管理員身分執行 PowerShell (怕資料夾或檔案鎖在管理員權限而無法刪除) # >D: # >CD D:\Buckup # >./ClearDbBackup.ps1 #定義主目錄 #透過Get-ChildItem抓該資料夾內的檔案列表 $TargetFolder = "D:\Backup\DB" #定義天數,要刪除多久以前的檔案 #若是要刪除30天前的檔案,$Days就設定30 $Days = 30 #取今日時間 $Currentlytime = (Get-Date).AddDays(-$Days) $Dirs = Get-Childitem -Path $TargetFolder -Recurse -Include *.bak foreach ($item in $Dirs) { #判斷檔案最後修改時間 #由LastWriteTime抓取檔案最後修改時間 #利用AddDays對$Currentlytime做時間的運算 if($item.LastWriteTime -le $Currentlytime) #-le 小於或等於 { Remove-Item $item.FullName | out-null write-host "Finish Deleting Dir $item" -ForegroundColor "DarkRed" } }
相關
- PowerShell 中文博客 - 收集和分享PowerShell相关教程,技术和最新动态