什么是必需的语法标准输入/输出上的Windows PowerShell重定向? 在Unix中,我们使用: $ /程序<&input.txt的GT; output.txt的 我如何在PowerShell中执行相同的任务? 解决方案 您不能直接挂钩一个文件到标准输入,但你仍然可以访问标准输入。获取内容input.txt中| ./program> output.txt的
以下是关于 powershell-v2.0 的编程技术问答
我正在建立一个小脚本,应将所有 .zip 文件复制到一个名为 F:\tempzip 。 我尝试使用 Copy- Item cmdlet,但我没有设法做到。脚本应该复制此文件夹中的所有文件(递归地)为“.zip”。 这是我所说的脚本的一部分: get-childitem F:\Work\xxx\xxx\xxx -recurse |其中{$ _。extension -eq“.zip”} | copy-item F:\tempzip 添加 解决方案 当将项目管道到 copy-item 告诉“F:\tempzip”是目标路径。 |复制项目目标F:\tempzip 您还可以将管道连接到 Get-ChildItem 的参数 -filter 运行 Get-Childitem“C:\imscript”-recurse -filter“* .zip”| Copy-Item -Destination“F:\temp
我正在尝试编译 cookie 感知 版本的 似乎找不到 CookieContainer 类型找不到(虽然它是完全合格的......) - 显然我对某些东西视而不见. 编辑:将示例代码更新为正确且可复制粘贴,谢谢! 解决方案 使用构造函数表达式对 CookieContainer 的第二次引用是完全限定的.声明字段 m_container 时的第一个引用不是.使两者都完全合格,以便 Powershell 可以找到它们 private System.Net.CookieContainer m_container = new System.Net.CookieContainer();
我有一个奇怪的问题,这是我的csv: Serveur;Carte;Cordon;IP;Mac;Vmnic ;Vmnic mac;Connect;Port Dexter;eth1;405;172.16.5.117;00:24:e8:36:36:df;Vmnic0;00:50:56:56:36:df;sw-front-1;A1 Dexter;eth2;14;192.168.140.17;00:24:e8:36:36:e1;Vmnic1;00:50:56:56:36:e1; sw_eq_ds_1;3 ;;;;;;;; Gordon;eth1;404;172.16.5.124;b8:ac:6f:8d:ac:b4;Vmnic0;00:50:56:5d:ac:b4;; Gordon;eth2;35;192.168.140.114;b8:ac:6f:8d:ac:b6;Vmnic1;00:50:56:5d:ac:b6;; Gordon;eth3;254;192.168.33.10;b8:ac:6f
是否有人知道是否可以在PowerShell v2.0中计算SHA1哈希? 我可以在线找到的唯一信息与powershell v4.0. 解决方案 我不记得在powershell v2天中,通常安装.NET 3.5.我认为这是这种情况. 您可以随时尝试以下内容,并查看它是否有效: $file = 'd:\scripts\sha1.ps1' $sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider [System.BitConverter]::ToString( $sha1.ComputeHash([System.IO.File]::ReadAllBytes($file))) 将$file的值用您拥有的文件的名称替换.
我试图在广告中的新创建的用户上设置一些权利. 创建文件夹后,我尝试设置这样的各种权限: $Rights = [System.Security.AccessControl.FileSystemRights]::FullControl $Inherit = @([System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.InheritanceFlags]::ObjectInherit) $Propagation = [System.Security.AccessControl.PropagationFlags]::None $Access =[System.Security.AccessControl.AccessControlType]::Allow $ACL = New-Object System.Security.Principal.NTAcco
我有一些辅助函数写入 STDOUT 以进行日志记录.其中一些函数会向调用者返回一个值,但会返回函数的整个输出.所以我的问题是如何让我的函数写入 STDOUT 并向调用者返回一个值,而返回值不会被函数调用期间发出的所有 STDOUT 污染?我正在寻找某种设计模式或最佳实践. 考虑这个脚本: Function a { Write-Output "In Function a" $a = 4 return $a } $b = a Write-Output "Outside function: `$b is $b" 输出是 Outside function: $b is In Function a 4 但我希望输出是: In Function a $b is 4 解决方案 在 PowerShell all 中返回函数内部未捕获的输出,而不仅仅是 return 的参数.从文档: 在 Windows PowerShell® 中,每
我的 Powershell (2.0) 脚本有以下代码片段: $fileName = "c:\reports\1.xlsx" $xl = new-object -comobject excel.application $xlFormat = [Microsoft.Office.Interop.excel.XlFileFormat]::xlWorkbookDefault $xl.displayalerts = $false $workbook = $xl.workbooks.open($fileName) #Code to manipulate a worksheet $workbook.SaveAs($fileName, $xlformat) $xl.quit() $error | out-file c:\reports\error.txt 我可以毫无问题地在 Powershell 命令提示符下运行此脚本.电子表格得到更新,error.txt 为空.但是,当我在任务计划程序中将其作
我正在编写一个简单的脚本来将广告组成员身到另一个用户复制到另一个用户.我只使用它使用激活的模块. 脚本看起来像它会起作用并且在我尝试向用户播放组之前工作. 代码: import-module ActiveDirectory $templateUser = get-ADUser user1 $targetUser = getADUser user2 $groups =get-adprincipalgroupmembership $templateUser $groups2 = get-ADPrincipalGroupMembership $targetUser foreach($group in $groups) { add-adGroupMember $group $targetUser } 错误: Add-ADGroupMember : insufficient access rights to performt the operation At
查看 PoshCode 上的 Get-WebFile 脚本:http://poshcode.org/3226我注意到这个对我来说很奇怪的装置: $URL_Format_Error = [string]"..." Write-Error $URL_Format_Error return 与此相反的原因是什么: $URL_Format_Error = [string]"..." Throw $URL_Format_Error 甚至更好: $URL_Format_Error = New-Object System.FormatException "..." Throw $URL_Format_Error 据我了解,您应该将 Write-Error 用于非终止错误,将 Throw 用于终止错误,因此在我看来,您不应使用 Write-Error 后跟 Return.有区别吗? 解决方案 Write-Error 如果你想通知用户一个非关键错误,应该使用.默认情况下,它所做的