powershell 入门_使用PowerShell入门的5个Cmdlet

powershell 入门

powershell 入门

image

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所具有的每个命令。

image

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 *

image

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 *

image

得到帮助 (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

获取帮助获取过程

image

获得会员(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。

image

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

获取流程| 获得会员

image

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”}

image

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 入门

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/279193.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Part 3: Services

介绍 在第3部分中,我们将扩展应用程序并启用负载平衡。为此,我们必须在分布式应用程序的层次结构中提升一个级别:服务。 StackServices (你在这里)Container (涵盖在第2部分中)关于服务 在分布式应用程序中,应用程序的不同部分被称为“服务”…

diy感应usb摄像头拍照_DIY无线感应充电器

diy感应usb摄像头拍照Courtesy of Instructables user Inducktion shares a very detailed tutorial on how to build a wireless power charger. He explains the impetus behind the project: 由Instructables用户提供Inducktion分享了有关如何构建无线电源充电器的非常详细…

常用模块之 time,datetime,random,os,sys

time与datetime模块 先认识几个python中关于时间的名词: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。我们运行“type(time.time())”,返回的是float类型。1970年之前的日期无法以此表…

使用aSpotCat控制您的Android应用权限

Viewing the permissions of each installed Android app requires digging through the Manage Applications screen and examining each app one by one — or does it? aSpotCat takes an inventory of the apps on your system and the permissions they require. 要查看每…

xtrabackup备份mysql“ib_logfile0 is of different”错误分析

今天用xtrabackup工具完整备份mysql数据库的时候出现“./ib_logfile0 is of different”错误,具体的日志信息如下: 我第一时间查询了百度和谷歌都没有找见相对应的答案。决定从错误日志入手,上面的日志提示说:mysql数据库inondb的日志文件的大…

如何使自己的不和谐机器人

Discord has an excellent API for writing custom bots, and a very active bot community. Today we’ll take a look at how to get started making your own. Discord具有出色的用于编写自定义机器人的API,以及非常活跃的机器人社区。 今天,我们将探…

​css3属性选择器总结

css3属性选择器总结 &#xff08;1&#xff09;E[attr]只使用属性名&#xff0c;但没有确定任何属性值 <p miaov"a1">111111</p> <p miaov"a2">111111</p> p[miaov]{background: red;} /*所有属性为miaov的元素都会被背景变红&a…

程序代码初学者_初学者:如何使用热键在Windows中启动任何程序

程序代码初学者Assigning shortcut keys to launch programs in Windows is probably one of the oldest geek tricks in the book, but in true geek fashion we are going to show you how to do it in Windows 8. 分配快捷键以在Windows中启动程序可能是本书中最古老的怪胎技…

stevedore——启用方式

2019独角兽企业重金招聘Python工程师标准>>> setuptools维护的入口点注册表列出了可用的插件&#xff0c;但是并没有为最终用户提供使用或启用的方法。 下面将描述用于管理要使用的扩展集的公共模式。 通过安装方式启用 对于许多应用程序&#xff0c;仅仅安装一个扩…

C# -- 文件的压缩与解压(GZipStream)

文件的压缩与解压 需引入 System.IO.Compression; 1.C#代码&#xff08;入门案例&#xff09; 1 Console.WriteLine("压缩文件...............");2 using (FileStream fr File.OpenRead("d:\\test.txt"))3 {4 …

win7屏保文件.scr_如何将屏保添加到Ubuntu 12.04

win7屏保文件.scrUbuntu 12.04 doesn’t ship with any screen savers, just a black screen that appears when your system is idle. If you’d rather have screensavers, you can swap gnome-screensaver for XScreenSaver. Ubuntu 12.04没有附带任何屏幕保护程序&#xff…

简单读写XML文件

IPAddress.xml 文件如下&#xff1a; <?xml version"1.0" encoding"utf-8"?><IP><IPAddress>192.168.0.120</IPAddress></IP> 在 Form 窗体(读取XML配置.Designer.cs)中有如下控件&#xff1a; 代码 privateSystem.Wind…

如何与Ubuntu One同步配置文件

Ubuntu One lets you easily synchronize files and folders, but it isn’t clear how to sync configuration files. Using Ubuntu One’s folder synchronization options or some symbolic links, you can synchronize configuration files across all your computers. Ubu…

智能家居设备_您的智能家居设备正在监视您吗?

智能家居设备In a world where we’re all paranoid about devices spying on us (and rightfully so), perhaps no other devices receive more scrutiny than smarthome products. But is that scrutiny warranted? 在一个我们都对监视设备的人都抱有偏执的世界(理应如此)&a…

Jenkins忘记admin密码处理方法

1、先找到enkins/config.xml文件&#xff0c;并备份。 此文件位于Jenkins系统设置的主目录&#xff0c;根据自己的配置情况而定。我的位置如下 /data/temp/jenkins/config.xml2、然后编辑config.xml删除<useSecurity>true</useSecurity>至</securityRealm>&a…

科研绘图工具软件_如何在Windows 10 Mail中使用绘图工具

科研绘图工具软件Microsoft recently released a new feature for the Windows 10 Mail app that lets you convey messages with drawings right inside the body of an email. This is a great way to quickly sketch things like graphs or tables to get your point across…

子元素相对于父元素垂直居中对齐

记个笔记 1. 元素相对于浏览器居中 <style>.window-center {/* 将position设置为fixed&#xff0c;使元素相对于浏览器窗口定位 */position: fixed;/* 将margin设置为auto&#xff0c;使浏览器自动推算元素外边距 */margin: auto;/* 将上下左右边距&#xff08;相对于浏览…

网站运行java_定制化Azure站点Java运行环境(5)

Java 8下PermGen及参数设置在上一章节中&#xff0c;我们定制化使用了Java 8环境&#xff0c;使用我们的测试页面打印出了JVM基本参数&#xff0c;但如果我们自己观察&#xff0c;会发现在MXBeans中&#xff0c;没有出现PermGen的使用数据&#xff0c;初始大小等信息&#xff0…

三阶魔方魔方公式_观看此魔方的自我解决

三阶魔方魔方公式Finally: a Rubik’s cube that can solve itself. A maker named Human Controller built it in Japan, and you can see it in action right now. 最后&#xff1a;一个可以解决自身问题的魔方。 一家名为Human Controller的制造商在日本制造了它&#xff0…

pc样式在ie8中的bug

2019独角兽企业重金招聘Python工程师标准>>> pc样式在ie8中的bug 1,box-sizing:border-box: 在ie中,此属性的使用有限制: (在IE8中&#xff0c;min-width属性适用于content-box即使box-sizing设置为border-box。 Chrome select在使用时从元素中选择选项时遇到问…