powershell 入门

PowerShell is quickly becoming the preferred scripting language and CLI of Power Users as well as IT Pros. It’s well worth learning a few commands to get you started, so we’ve got 5 useful cmdlets for you to learn today.

PowerShellSwift成为高级用户和IT专业人员的首选脚本语言和CLI。 值得学习一些命令以使您入门非常值得,因此,我们今天有5个有用的cmdlet供您学习。

获取命令 (Get-Command)

The Get-Command is one of the most useful cmdlets in the whole of PowerShell, as it will help you getting to grips with PowerShell by letting you search for certain cmdlets. Using Get-Command on its own is admittedly not very useful as its just going to spit out every command that PowerShell has.

Get-Command是整个PowerShell中最有用的cmdlet之一,因为它可以通过搜索某些cmdlet来帮助您掌握PowerShell。 单独使用Get-Command并不是很有用,因为它只会吐出PowerShell所具有的每个命令。

But from this we can see that that objects that PowerShell outputs have both a Name and a ModuleName property. Using this information we can fine grain our search, by searching for cmdlets that contain certain terms. For example if I wanted to find all cmdlets that contain the word “IP”, I could do this:

但是从中我们可以看到PowerShell输出的对象同时具有Name和ModuleName属性。 使用此信息,我们可以通过搜索包含某些术语的cmdlet来细化搜索范围。 例如,如果我想查找所有包含单词“ IP”的cmdlet,则可以这样做:

Get-Command –Name *IP*

Get-Command –名称* IP *

As you can see we still get quite a few results, our next option is to search within a specific module. In our case i will choose the NetTCPIP module.

如您所见,我们仍然可以获得很多结果,我们的下一个选择是在特定模块内搜索。 在我们的情况下,我将选择NetTCPIP模块。

Get-Command –Module NetTCPIP –Name *IP*

获取命令–模块NetTCPIP –名称* IP *

得到帮助 (Get-Help)

Once you have found the cmdlet you are looking for using Get-Command, you are going to want to know the syntax and how you can use that specific cmdlet. This is where Get-Help comes in, if you have ever used the command line in Windows you probably did something like this:

找到要使用Get-Command查找的cmdlet后,您将想要了解语法以及如何使用该特定cmdlet。 这是获取帮助的地方,如果您曾经在Windows中使用过命令行,则可能会执行以下操作:

ipconfig /?

ipconfig /?

Well that doesn’t work in PowerShell, this is because in PowerShell a space is used to separate a command from its parameters. So instead we use Get-Help and pass a cmdlets name to Get-Help as a parameter.

嗯,这在PowerShell中不起作用,这是因为在PowerShell中,空格用于将命令与其参数分开。 因此,我们改为使用Get-Help并将cmdlet名称作为参数传递给Get-Help。

Get-Help Get-Process

获取帮助获取过程

获得会员(Get-Member)

Get-Member allows us to get information about the objects that a cmdlets returns. The catch with get-member, is that it relies on PowerShell’s pipeline feature, to demonstrate this, we will can use the Get-Process cmdlet.

Get-Member允许我们获取有关cmdlet返回的对象的信息。 get-member的不足之处在于,它依赖于PowerShell的管道功能,对此进行演示,我们将可以使用Get-Process cmdlet。

As you can see PowerShell’s output shows us some of the properties, which you can see at the top of each column. The first problem is that, while those are the properties you might be looking for most of the time, there are still more of them. The second problem is that it doesn’t show any methods that we are able to call on the object. To see the methods and properties we can pipe our output to Get-Member, like so:

如您所见,PowerShell的输出向我们显示了一些属性,您可以在每一列的顶部看到这些属性。 第一个问题是,尽管大多数时候这些属性是您可能一直在寻找的,但仍有更多的属性。 第二个问题是它没有显示我们可以在对象上调用的任何方法。 要查看方法和属性,我们可以将输出通过管道传递到Get-Member,如下所示:

Get-Process | Get-Member

获取流程| 获得会员

While it may mean nothing to you right now, you will sooner or later need to use Get-Member, and the sooner you learn to use it the better. As an example, using the information from the output we could do something like:

尽管这可能对您现在没有任何意义,但是您迟早需要使用Get-Member,并且越早学会使用它就越好。 例如,使用输出中的信息,我们可以执行以下操作:

Start-Process notepad.exe $NotepadProc = Get-Process -Name notepad $NotepadProc.WaitForExit() Start-Process calc.exe

Start-Process notepad.exe $ NotepadProc =获取进程-Name记事本$ NotepadProc.WaitForExit()Start-process calc.exe

That script will launch notepad,  it then assigns output of “Get-Process –Name notepad” to the $NotepadProc variable, then we call the WaitForExit method on $NotepadProc which causes the script to pause  until you close notepad, once you have closed notepad then the calculator will launch.

该脚本将启动记事本,然后将“ Get-Process –Name notepad”的输出分配给$ NotepadProc变量,然后在$ NotepadProc上调用WaitForExit方法,这将导致脚本暂停,直到您关闭记事本为止。然后计算器将启动。

$ _(当前管道对象) ($_(Current Pipeline Object))

While not exactly a cmdlet, it is one of the most used special variables in PowerShell. The official name for $_ is “the current pipeline object” . It is used in script blocks, filters, the process clause of functions, where-object, foreach-object and switches. However it is easier to explain with an example, which brings us to our next and final cmdlet, Where-Object.

虽然不完全是cmdlet,但它是PowerShell中最常用的特殊变量之一。 $ _的正式名称是“当前管道对象”。 它用于脚本块,过滤器,函数的处理子句,where对象,foreach对象和开关。 但是,通过示例更容易解释,该示例将我们带入下一个也是最后一个cmdlet Where-Object。

对象在哪里 (Where-Object)

Where-Object does exactly what it sounds like, it selects an object based on whether it meets a certain criteria. This will bring together $_, and the properties we can see using Get-Member. To demonstrate this, we will pipe the output of Get-Process into the Where-Object cmdlet.

Where-Object完全按照听起来的样子运行,它根据是否满足特定条件来选择对象。 这将集合$ _和我们可以使用Get-Member看到的属性。 为了说明这一点,我们将把Get-Process的输出传递到Where-Object cmdlet中。

Get-Process | Where-Object {$_.Name –eq “iexplore”}

获取流程| 哪里对象{$ _。Name –eq“ iexplore”}

So what’s going on here you ask? Well the first thing we are doing is getting a list of processes on our computer and passing the output (using the | character) to our Where-Object cmdlet,  which takes a script block  as a parameter. The script block (defined by the curly braces) instructs the Where-Object cmdlets to only select objects where their name parameter is equal to “iexplore”, and so we only get a list of the IE instances that are running. That’s all there is to it, have fun!

那你问这是怎么回事? 好吧,我们要做的第一件事是获取计算机上的进程列表,并将输出(使用|字符)传递给Where-Object cmdlet,该cmdlet将脚本块作为参数。 脚本块(由花括号定义)指示Where-Object cmdlet仅选择其名称参数等于“ iexplore”的对象,因此,我们仅获得正在运行的IE实例的列表。 这就是全部,玩得开心!

翻译自: https://www.howtogeek.com/114344/5-cmdlets-to-get-you-started-with-powershell/

powershell 入门

powershell 入门_使用PowerShell入门的5个Cmdlet相关推荐

  1. powershell 使用_使用PowerShell提取Azure成本

    powershell 使用 With strong organization and design for our development teams, cloud infrastructure an ...

  2. 数据分析师入门_数据分析师入门基础指南

    数据分析师入门 Back in the summer of 2018, I was just starting my first internship as a Data Analyst. 早在201 ...

  3. apache phoenix 入门_实现Phoenix入门

    快速入门 Phoenix是一个开源的HBASE SQL层.Phoeinx可以用标准的JDBC API替代HBASE client API来创建表,插入和查询查询HBASE中的数据. Phoenix作为 ...

  4. python最简易入门_零基础入门python,用最简单的方式即可入门python,没有那么复杂...

    python已经开始被越来越多的人喜欢,其中有很多是从未学习过编程的人,那么,如果是从零开始学python的话,会很难吗? 其实从零开始学python并不会很难,最简单的方法,往往最有效果,无论你是否 ...

  5. opencv入门_【OpenCV入门之十八】通过形态学操作提取水平与垂直线

    小白导读 学习计算机视觉最重要的能力应该就是编程了,为了帮助小伙伴尽快入门计算机视觉,小白准备了[OpenCV入门]系列.新的一年文章的内容进行了很大的完善,主要是借鉴了更多大神的文章,希望让小伙伴更 ...

  6. winexec函数 执行powershell 脚本_丢掉 Powershell.exe 来渗透测试

    0x00 前言 作为一个 pentest,真的是不需要 Powershell 吗?如果是,我真的会觉得不可思议. 但是,如果是因为某些策略,阻止了你对 powershell.exe 的访问,那该怎么办 ...

  7. powershell快捷键_关于powershell的知识你知道多少呢

    说起命令行,大家一定会想到电影中顶尖黑客敲打键盘.满屏字符滚动的场景.随着微软对 Win10 系统的不断升级,内置的默认命令行工具也逐渐从 Cmd 迁移到了 PowerShell众所周知,电脑中都有c ...

  8. 上位机plc编程入门_【新手入门】西门子PLC编程入门学习

    一.S7-200PLC 的硬件结构及系统构成.安装与接线学习 1.学习什么内容?重点学习什么内容? (1)PLC的硬件结构 (2)PLC的系统构成及CPU和模块参数 (3)PLC的选型,安装及接线(重 ...

  9. 互联网金融业务入门_在线业务入门

    互联网金融业务入门 Kick-starting your Online Business.启动您的在线业务. Are you thinking of starting your Online Busi ...

最新文章

  1. SolverParameter
  2. 支持向量机python代码实现
  3. CVPR 2022|从原理和代码详解FAIR的惊艳之作:全新的纯卷积模型ConvNeXt
  4. 2.sort 排序命令讲解
  5. python分享文件_使用简单的python http服务共享文件
  6. Spring Boot中日志框架的使用——Logback
  7. 如何用编程 get 百万年终奖?
  8. 6410 android 4.4.2,365备用「永久地址0365.tv」飞凌嵌入式开发板飞凌i.MX6开发板 Android 系统编译...
  9. STC学习:可同步显示歌词的ABC英文歌
  10. cpu压测 windows_小白求问怎么用AIDA64进行CPU压力测试
  11. C程序实例1--个人通讯录管理系统
  12. 计算机A类会议 icip,计算机视觉|中国计算机学会推荐国际学术刊物/会议
  13. Linux驱动——mmc bus浅析(五)
  14. ROS运行时出现Couldn‘t find executable错误
  15. Redis 面试面面观
  16. Predicting Buffer Overflow Vulnerabilities through Mining Light-Weight Static Code Attributes
  17. Emlog最新文章采集插件
  18. 戏说领域驱动设计(十二)——服务
  19. oracle 12c pdb 备份,12c PDB备份与恢复初体验
  20. SpiderMonkey 入门翻译

热门文章

  1. .Net架构必备工具列表
  2. linux开发板上程序如何调试,linux开发板调试典型方法
  3. python excel模板 插件_python脚本——自动推送txt,EXCEL等文件模板
  4. python主从_python—mariadb自动部署主从
  5. java记事本复制粘贴_Java Swing 如何实现记事本中“编辑”菜单下的 剪切,复制,粘贴,删除,全选 功能...
  6. 利用自定命令打开常用软件,小白秒变大神。
  7. 我很喜欢玩游戏,那么我就适合做游戏程序员吗?
  8. 表达能力VS只会敲代码(2018届毕业生web前端)
  9. .Net Core创建Docker镜像
  10. ubuntu7.10安装到3D开启