PowerShell Beginner’s Guide 教程笔记

这篇博客是作者学习PowerShell Beginner’s Guide教程的笔记,涵盖了get-process命令的使用,PowerShell版本差异,别名操作,文件和目录管理,以及脚本执行等内容。特别提到在PowerShell中,使用`#`作为注释,以及如何在不同版本中运行和查看进程。文章还提到了在Windows环境下运行PowerShell脚本的安全策略和解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PowerShell Beginner’s Guide 教程笔记

前言

PowerShell Beginner’s Guide 是 PowerShell 官方的入门教程。以下是我学习该教程时的笔记。

笔记

  1. get-process命令。

    Get-Process: Gets the processes that are running on the local computer or a remote computer.

    需要注意的是这个命令在 5.1 版本,和 7.0 版本返回结果略有不同,5.1 版本多了 handles 这一对象。

    可以通过指定名称的方式,获取指定进程信息。

    # 14747 at SUPER-ALPHA in D:\shellCode [14:02:27]
    ➜ get-process -name wiz
    
    Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
    -------  ------    -----      -----     ------     --  -- -----------
       1114      82    41976      17184      36.55  25264   4 Wiz
    

    多对象用逗号隔开即可:

    # 14747 at SUPER-ALPHA in D:\shellCode [14:02:46]
    ➜ Get-Process -n wiz,tim
    
    Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
    -------  ------    -----      -----     ------     --  -- -----------
       1329     306   144016      91816      54.19  17136   4 TIM
       1450    1056   256432     172324     658.11  21064   4 TIM
       1114      82    42100      17272      36.59  25264   4 Wiz
    
  2. Clear-Host 清屏操作(Clears the display in the host program)。它有两个别名(alias)clsclear

  3. Get-Alias 命令可以查看当前会话中的别名(Gets the aliases for the current session)。

  4. cd $home 可以回到 home 目录。

  5. new-item 新建子目录或文件时,若已经存在同名文件会报错,这时可以用 -force 强制执行:

    # 14747 at SUPER-ALPHA in D:\shellCode [13:20:02]
    ➜ New-Item -path temp1/fuckyou.txt -value "fuck you,asshole"
    
        Directory:  D:\shellCode\temp1
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -a---          2019/9/5     13:22       16   fuckyou.txt
    
    # 14747 at SUPER-ALPHA in D:\shellCode [13:22:35]
    ➜ New-Item temp1/fuckyou.txt -value "fuck you,asshole"      
    New-Item : The file 'D:\shellCode\temp1\fuckyou.txt' already exists.
    At line:1 char:1
    + New-Item temp1/fuckyou.txt -value "fuck you,asshole"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (D:\shellCode\temp1\fuckyou.txt:String) [New-Item], IOException
    + FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand
    
    
    # 14747 at SUPER-ALPHA in D:\shellCode [13:22:59]
    ➜ New-Item temp1/fuckyou.txt -value "fuck you,asshole" -force
    -a---          2019/9/5     13:23       16   fuckyou.txt
    
  6. set-content 命令也可以设置文件内容,若文件不存在会自动创建文件,但是上级的文件夹不会自动创建。

    # 14747 at SUPER-ALPHA in D:\shellCode [13:36:03]
    ➜ set-content temp1\new.txt -value "fuck you"
    
    # 14747 at SUPER-ALPHA in D:\shellCode [13:36:11]
    ➜ ls temp1
    -a---         2019/8/30     19:00       38   another.txt
    -a---          2019/9/5     13:35       17   fuckyou.txt
    -a---         2019/8/19      1:34    11.86KB mytest.html
    -a---          2019/9/5     13:36       10   new.txt
    -a---         2019/8/30     18:49       10   test1.txt
    -a---          2019/9/4     15:15        0   test11.txt
    -a---          2019/9/4     15:15        0   test12.txt
    -a---         2019/8/30     18:50       11   test2.txt
    -a---         2019/8/30     18:58     1.79KB test3.txt
    -a---         2019/8/30     19:00       38   test4.txt
    
    # 14747 at SU
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

半美人

动力源于鼓励

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

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

打赏作者

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

抵扣说明:

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

余额充值