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

前言

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东北小狐狸-Hellxz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值