您的位置:首页 > 运维架构 > Linux

Win10 Powershell实现类似Linux指定tree命令展示深度

2020-02-10 18:33 921 查看

前言

今天又是远程上班的一天,愿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) [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 深度数
,就可以了(目录如果是当前,可以省略)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: