关于PowerShell中PassThru的实际作用
来源:互联网 发布:淘宝售后管理软件 编辑:程序博客网 时间:2024/05/22 14:31
在PowerShell中,我相信你一定看到过PassThru参数但是这个参数主要是做什么用的呢?其实很多人没有完全搞明白,今天我们就来看看主要是做什么用的。
在进一步了解之前,首先要让大家知道的是并不是所有的cmdlet命令都有这个PassThru参数,因为这并不是一个公共参数。
我们先来看看,在PowerShell中有哪些命令是支持PassThru这参数的,我们可以用如下命令行查看:
PS C:\windows\system32> Get-Command -CommandType cmdlet|?{$_.Definition -match 'PassThru'}CommandType Name Version Source----------- ---- ------- ------Cmdlet Add-Computer 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Add-Content 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Add-History 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Add-PSSnapin 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Clear-ItemProperty 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Copy-Item 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Copy-ItemProperty 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Import-Module 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Move-Item 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Move-ItemProperty 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet New-ModuleManifest 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Pop-Location 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Push-Location 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Remove-Computer 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Remove-PSSnapin 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Rename-Computer 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Rename-Item 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Rename-ItemProperty 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Restart-Service 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Resume-Service 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Set-Content 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Set-Item 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Set-ItemProperty 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Set-Location 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Set-Service 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Start-Process 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Start-Service 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Stop-Job 3.0.0.0 Microsoft.PowerShell.CoreCmdlet Stop-Process 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Stop-Service 3.1.0.0 Microsoft.PowerShell.ManagementCmdlet Suspend-Service 3.1.0.0 Microsoft.PowerShell.Management
PS C:\windows\system32> Rename-Item -Path D:\test.txt -NewName D:\test2.txt如上命令我们使用Rename-Item cmdlet将D盘下的一个test文本文件重命名为test2,但是当你按回车,顺利执行完后并没有出现任何信息,除非是报错。
现在我们添加上PassThru参数试一下,你会发现该参数其实就是把执行后原本隐藏的对象信息又显示出来了。
PS C:\windows\system32> Rename-Item -Path D:\test2.txt -NewName D:\test.txt -PassThru Directory: D:\Mode LastWriteTime Length Name---- ------------- ------ -----a---- 2016/6/12 23:00 0 test.txt
我们可以在换一个命令来测试下区别,下面我们用Move-Item来删除指定路径下的文件,当我们不指定PassThru参数的时候我们会发现当命令成功顺利执行完后,并没有显示任何信息。但是,当我们添加了PassThru你会发现Console界面输出了所删除的文件的相关对象信息。
PS C:\windows\system32> Move-Item -Path D:\test.txtPS C:\windows\system32> Move-Item -Path D:\test2.txt -PassThru Directory: C:\windows\system32Mode LastWriteTime Length Name---- ------------- ------ -----a---- 2016/6/12 23:05 0 test2.txt
0 0
- 关于PowerShell中PassThru的实际作用
- PowerShell中的PassThru参数是什么
- PHP中关于队列的实际应用
- 实际开发中关于autorelease的运用
- 关于PowerShell中的Hidden关键字作用
- 关于PowerShell中创建受信任的脚本
- 一篇关于在PowerShell中编译c#的文章
- 翻译了passthru中protocol.c的注释
- PHP中调用系统命令的system(),exec(),passthru()
- PHP中调用系统命令的system(),exec(),passthru()。。。。。。。。
- UIViewControllerBasedStatusBarAppearance作用的实际测试
- 【转帖】passthru的说明书!!!
- passthru的说明书
- 关于windows powershell的想法
- 关于log4j在实际工作中使用的一些想法
- 实际项目中关于java常量宏替换的实际问题
- DECLARE_DYNCREATE 和 IMPLEMENT_DYNAMIC 的一个实际作用
- ios::binary方式的实际作用
- (第三季)205-int类型的冒泡排序 206-拓展的通用的冒泡排序方法
- 20160429待整理
- hibernate的抓取和级联操作
- 机器学习之EM算法解析
- 一个字符解决Gradle aar编译参数传递问题是怎样一种体验
- 关于PowerShell中PassThru的实际作用
- tomcat部署solr
- 分布式Unique ID的生成方法一览
- C语言文件读写操作总结
- 数据库之768,702版本之间问题
- jBPM4.4中配备MySQL的hibernate方言MySQLInnoDBDialect
- Android Monkey测试工具的使用
- 黑科技:程序猿如何打造属于自己的分体键盘
- 运用委托是注意异步调用