【发布时间】:2017-07-24 13:11:15
【问题描述】:
我有一个 Linux 和 Windows 的混合环境,但是构建脚本是用 Ruby 创建的。我正在尝试在涉及 PSRemoting 的每个 Web 服务器上进行一些更改,但看起来我在将字符串转换为 powershell 命令时遇到了一些问题:
puts "%x{ powershell.exe invoke-command -computername #{server} -scriptblock { $oldpath = #{current_iis_site_folder}; $newpath = #{new_site_folder}; Get-ChildItem -Path $oldpath -Recurse | where {($_.FullName -notmatch $oldpath.replace('\\','\\\\')) -or ($_.FullName -notmatch $newpath.replace('\\','\\\\'))}} }.strip.downcase"
%x{ powershell.exe invoke-command -computername #{server} -scriptblock { $oldpath = #{current_iis_site_folder}; $newpath = #{new_site_folder}; Get-ChildItem -Path $oldpath -Recurse | where {$_.FullName -notmatch "corehr"}} }.strip.downcase
这个产品是:
%x{ powershell.exe invoke-command -computername iistest.neogov.net -scriptblock { $oldpath = c:\webdata\corehr; $newpath = c:\webdata\corehr\07241439; Get-ChildItem -Path $oldpath -Recurse | where {($_.FullName -notmatch $oldpath.replace('\','\\')) -or ($_.FullName -notmatch $newpath.replace('\','\\'))}} }.strip.downcase
'where-object' 不是内部或外部命令、可运行程序或批处理文件。
如果我只用where 替换where-object,那么错误会有所不同:
语句块或类型定义中缺少结束“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace
信息:找不到给定模式的文件
我认为管道 (|) 可能会让 ruby 解释器感到困惑,但不知道如何避免?
【问题讨论】:
标签: ruby powershell devops