2K+ 次瀏覽
當向 Get-ChildItem cmdlet 提供專案(檔案)路徑時,它會提取檔案資訊,例如名稱、上次寫入時間、大小等。示例 Get-ChildItem -Path D:\Temp\style.css 輸出 Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 08-12-2017 10:16 393 style.css 命令 若要獲取檔案的完整屬性,則需要使用 fl * (Format-List *) 管道命令。Get-ChildItem -Path D:\Temp\style.css | fl * 輸出 PSPath : Microsoft.PowerShell.Core\FileSystem::D:\Temp\style.css ... 閱讀更多
260 次瀏覽
Get-ChildItems 支援以下引數:Get-ChildItem[[-Path] ] [[-Filter] ] [-Include ] [-Exclude ] [-Recurse] [-Depth ] [-Force] [-Name] [-Attributes ] [-FollowSymlink] [-Directory] [-File] [-Hidden] [-ReadOnly] [-System] []
350 次瀏覽
有一些方法或函式可用於目錄和檔案操作。目錄的方法。TypeName: System.IO.DirectoryInfo Name MemberType ---- ---------- Create Method CreateObjRef Method CreateSubdirectory Method Delete Method EnumerateDirectories Method EnumerateFiles Method EnumerateFileSystemInfos Method Equals Method ... 閱讀更多
3K+ 次瀏覽
當您將引數 Get-Member (別名 gm) 透過管道傳遞並篩選出屬性時,將顯示兩種不同的屬性。一種是用於檔案,另一種是用於資料夾。Get-ChildItem 屬性 命令 Get-ChildItem | gm | where{$_.Membertype -eq "Property"} 輸出 ** 目錄屬性 TypeName: System.IO.DirectoryInfo Name MemberType Definition ---- ---------- Attributes Property System.IO.FileAttributes Attributes {get;set;} CreationTime Property datetime CreationTime {get;set;} CreationTimeUtc Property datetime CreationTimeUtc {get;set;} Exists Property bool Exists {get;} Extension ... 閱讀更多
980 次瀏覽
PowerShell 中的 Get-ChildItem(別名:dir)用於獲取容器內的專案。此容器可以是資料夾、登錄檔或證書儲存區。您可以從一個或多個指定位置檢索專案。此命令的工作方式類似於命令提示符中的 dir,但 PowerShell 提供了一種更現代的方式來提取資料。
828 次瀏覽
在使用 PowerShell 中的 Stop-Process 命令終止程序後,可以使用 HasExited 函式確定程序是否真的已從系統中終止。例如,我們將終止記事本程序並檢查記事本程序是否仍然存在於系統中?$notepad = Get-Process notepad | Stop-Process if($notepad.HasExited){"程序已終止"} else{"程序仍在執行"}
使用 Passthru 引數,PowerShell 會在控制檯中返回輸出。例如,以下 ID 為 12344 的 notepad.exe 程序將被停止,並且使用 Passthru 引數會在控制檯中顯示相同的內容。以前,僅使用 Stop-Process 時並非如此。PS C:\WINDOWS\system32> Stop-Process -Id 12344 -Passthru Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 227 13 2800 13440 0.19 12344 1 ... 閱讀更多
277 次瀏覽
要在停止程序或例項之前獲得使用者的同意,可以使用 -confirm 引數。示例 在下面的示例中,我們將使用 –Confirm 引數停止 ID 為 4900 的 notepad.exe 程序。PS C:\WINDOWS\system32> Stop-Process -Id 4900 -Confirm 確認 您確定要執行此操作嗎? 對目標“notepad (4900)”執行操作“Stop-Process”。 [Y] 是 [A] 全部是 [N] 否 [L] 全部否 [S] 暫停 [?] 幫助(預設值為“Y”): 同樣,您可以使用 –Confirm 引數透過名稱停止程序。PS C:\WINDOWS\system32> Stop-Process -Name Notepad -Confirm
290 次瀏覽
要停止程序的特定例項,需要向 Stop-Process cmdlet 提供程序 ID。示例 在下面的示例中,我們需要停止例項 ID 為 25400 的 Notepad 程序。輸出 Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 228 14 3156 13680 0.13 4900 1 notepad 232 14 3196 13752 0.16 25400 1 notepad Stop-Process -Id 25400 現在,執行 Get-Process 命令時,將沒有使用 –Id 25400 執行的程序。命令 PS C:\WINDOWS\system32> Get-Process -Name notepad 輸出 Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 227 13 2808 13492 0.14 4900 1 notepad
要在 PowerShell 中停止所有正在執行的程序例項,可以使用 Stop-Process 命令。例如,在下面的示例中,我們有兩個正在執行的 notepad.exe 程序例項。命令 PS C:\WINDOWS\system32> Get-Process notepad 輸出 PS C:\WINDOWS\system32> Get-Process notepad Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 228 13 3160 13448 0.14 15564 1 notepad 228 14 3148 13668 0.17 22644 ... 閱讀更多