0

I am getting an error while executing the below. Is the below method to concatenate $env:userprofile with path correct?

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

Error:

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

Thanks for the help

John

1
  • 1
    Concatenating paths like that only works in argument-mode - prepend the entire thing with the call operator & and it'll work: & $env:userprofile\Documents\DNS\GetDnsRecord.ps1 | ... Commented Aug 12, 2020 at 11:24

1 Answer 1

1

You might want to read a bit about Join-Path: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path?view=powershell-7

Join-Path $env:userprofile '\Documents\DNS\GetDnsRecord.ps1'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.