前言
今天又是遠程上班的一天,願NCP病毒早日過去……
用慣了Linux上的tree命令來展示目錄結構,今天遠程Win10上,需要通過目標結構寫一些腳本,查看了下Powershell是默認有個tree命令的,但是不支持指定深度
所以,這篇文章主要是實現tree命令展示指定深度的目錄結構功能
看了下Powershell官網的確有這個插件,描述是下邊這shai er 的,大意是實現了命令行的通用功能 官網
PowerShell Community Extensions (PSCX) base module which implements a general purpose set of Cmdlets.
安裝Powershell插件——Pscx
安裝Pscx 3.2.2, 前邊的命令是說安裝這個插件的指定版本,后邊的-Scope CurrentUser
表示此擴展僅作用於當前登錄用戶,-AllowClobber
是安裝時提示這個模塊會覆蓋現有命令的錯誤,規避它使用此參數
Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber
出現如下提示,直接輸入A,回車
PS D:\com-workspace\enterprise> Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber
不受信任的存儲庫
你正在從不受信任的存儲庫安裝模塊。如果你信任該存儲庫,請通過運行 Set-PSRepository cmdlet 更改其 InstallationPolicy
值。是否確實要從“PSGallery”安裝模塊?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暫停(S) [?] 幫助 (默認值為“N”): A
測試
Pscx擴展中有個命令叫做Show-Tree
,查看此命令的參數列表可以有哪些
PS D:\com-workspace\enterprise> get-help show-tree
名稱
Show-Tree
摘要
Shows the specified path as a tree.
語法
Show-Tree [[-Path] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-Excl
udeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>]
Show-Tree [[-LiteralPath] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty]
[-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>]
說明
Shows the specified path as a tree. This works for any type of PowerShell provider and can be used to explore prov
iders used for configuration like the WSMan provider.
相關鏈接
備注
若要查看示例,請鍵入: "get-help Show-Tree -examples".
有關詳細信息,請鍵入: "get-help Show-Tree -detailed".
若要獲取技術信息,請鍵入: "get-help Show-Tree -full".
使用Show-Tree 目錄 -Depth 深度數
,就可以了(目錄如果是當前,可以省略)