Powershell脚本语法问题

用户名
$Source = "[source]"   
$Destination = "[destination]"


xcopy $Source\* $Destination /Y

Get-ChildItem -path $Destination\* -Include *.zip,*.rar,*.7z | %{ 
    if($_.Name -match "^*.'.zip$" -or $_.Name -match "^*.'.7z$" -or $_.Name -match "^*.'.rar$"){
        $parent="$(Split-Path $_.FullName -Parent)";    
        $arguments=@("x", "'"$($_.FullName)'"", "-o'"$($parent)'" -y");
        $ex = start-process -FilePath "'"C:\Program Files\7-Zip\7z.exe'"" -ArgumentList $arguments -wait -PassThru;
        if( $ex.ExitCode -eq 0){
            rmdir -Path $_.FullName -Force
        }
    }
}
rmdir -Path $Source\* -recurse -Force

当我尝试运行此脚本时,出现以下错误:

Unexpected token '$(' in expression or statement.
At D:\Bluedoor\WealthNET Files\Interface Data\RMS\Untitled3.ps1:10 char:32
+         $arguments=@("x", "'"$( <<<< $_.FullName)'"", "-o'"$($parent)'" -y");
    + CategoryInfo          : ParserError: ($(:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken.
联合会

不确定确切要做什么,但是您应该尝试执行以下操作:

$arguments=@("x", "$($_.FullName)", "-o`"$($parent)`"", "-y");

-o参数中的`(反引号)允许您在由双引号引起来的字符串中使用“(双引号)。

Get-ChildItem t.txt | % {$parent="coucou";$arguments=@("x", "$($_.FullName)", "-o`"$($parent)`"", "-y");$arguments}

给出:

x
C:\temp\t.txt
-o"coucou"
-y

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Powershell IF语句语法问题

来自分类Dev

嵌入Powershell脚本问题

来自分类Dev

PowerShell脚本问题

来自分类Dev

加载groovy脚本时出现语法问题

来自分类Dev

C#执行Perl脚本-语法问题?

来自分类Dev

PDO 脚本中的 mySQL 语法问题

来自分类Dev

系统日志的 PowerShell 脚本问题

来自分类Dev

批量删除脚本的 PowerShell 问题

来自分类Dev

PnP PowerShell 代码语法错误问题

来自分类Dev

Windows Powershell脚本中的服务解释问题

来自分类Dev

在PowerShell脚本中替换新行的问题

来自分类Dev

我的Powershell脚本出了什么问题?

来自分类Dev

Powershell 中的奇怪脚本问题

来自分类Dev

如何在C#中验证PowerShell脚本语法?

来自分类Dev

Azure Devops Yaml构建定义PowerShell内联语法问题

来自分类Dev

PowerShell $ _语法

来自分类Dev

使用PowerShell脚本安装COM +组件时的问题

来自分类Dev

执行.ps1脚本时的Powershell问题

来自分类Dev

解决在Powershell中将Destination参数作为脚本块编写的问题

来自分类Dev

Powershell问题:尝试为非管理用户运行安装脚本

来自分类Dev

Bash Shell脚本编写有关语法和基本名称的基本问题

来自分类Dev

脚本问题

来自分类Dev

在不先运行 VB 脚本的情况下运行 Powershell 脚本的问题

来自分类Dev

了解bash脚本语法

来自分类Dev

预制脚本的语法

来自分类Dev

DSQL语法ETL脚本

来自分类Dev

For循环语法bash脚本

来自分类Dev

Bash脚本-exec语法

来自分类Dev

Bash脚本,OR语句的语法