0
nuget pack C:\Users\%USERNAME%\Source\Repos\Common\Common\Common.nuspec -OutputDirectory D:\NugetFeed

The above code is what is in my nugetpack.ps1 file. It works perfectly when I directly enter my username is the path, but I need it to be able to work for multiple users. I entered the %USERNAME% username variable into the path but I get the following response:

Could not find a part of the path 'C:\Users\%USERNAME%\Source.....'.

How can I use the %USERNAME% variable in my path. I am new to PowerShell.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
TroySteven
  • 4,885
  • 4
  • 32
  • 50

1 Answers1

2

Environment variables in PowerShell are on the logical drive env:, but are otherwise syntactically normal PowerShell variables. The use of %...% is BATCH syntax. For PowerShell, use $env:varname, e.g., $env:username.

You may also find that you need the information in "Run Executable From PowerShell Script With Parameters".

Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33