首页 > 解决方案 > Powershell 错误 - 意外的令牌错误

问题描述

执行以下操作时出现错误。以下将 $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.

谢谢您的帮助

约翰

标签: powershell

解决方案


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

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

推荐阅读