【问题标题】:Powershell error - Unexpected token errorPowershell 错误 - 意外的令牌错误
【发布时间】:2020-08-12 22:54:32
【问题描述】:

执行以下操作时出现错误。以下将 $env:userprofile 与路径连接的方法是否正确?

$env:userprofile\Documents\DNS\GetDnsRecord.ps1 | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append $env:userprofile\Documents\DNS\DnsRecord.csv

错误:

 + $env:userprofile\Documents\DNS\GetDnsRecord.ps1 | ConvertTo-Csv -NoTy ...
 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '\Documents\DNS\GetDnsRecord.ps1' in expression or statement.

感谢您的帮助

约翰

【问题讨论】:

  • 像这样的连接路径仅适用于参数模式 - 使用调用运算符 & 预先添加整个内容,它会起作用:& $env:userprofile\Documents\DNS\GetDnsRecord.ps1 | ...

标签: powershell


【解决方案1】:

您可能想了解一下 Join-Path:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path?view=powershell-7

Join-Path $env:userprofile '\Documents\DNS\GetDnsRecord.ps1'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 2015-11-19
    • 2018-08-27
    • 2014-12-07
    • 2016-08-10
    相关资源
    最近更新 更多