3

Good Day

I am trying to set these paths in powershell but have not been successful in this regard. I have a DOS script that was initially written to set these paths but now I need it set in powershell.

Primarily, these paths are still used in the script to parse information, so in the same breathe, should act as a variable as well. Please help if possible. I am aware that powershell has a Set-Location function but would it serve the purpose as described above. Here are the paths scripted in DOS below:

   set CLASSPATH=D:\NetExpress\Base\Bin\WIN64\mfcobol.jar;.;%CLASSPATH%
   set COBIDY=D:\NetExpress\Base\SOURCE
   set COBLINK64=D:\NetExpress\Base\Bin\Linker
   set COBREG_64_PARSED=True
   set INCLUDE=D:\NetExpress\Base\INCLUDE
   set LIB=D:\NetExpress\Base\Lib\WIN64
   set MFTRACE_LOGS=D:\NetExpress\Base\MFTRACE\Logs
   set SCHEMA_PATH=D:\NetExpress\Base\SCHEMA
   set TXBIN=D:\NetExpress\Base
   set TXDIR=D:\NetExpress\Base
   set PATH=D:\NetExpress\Base\Bin\Linker;D:\NetExpress\Base\Bin\WIN64;D:\NetExpress\Base\Bin;D:\NetExpress\PACKAGES\x64;C:\Windows\System32\wbem;C:\Windows\System32\
   set COBPATH64=D:\NetExpress\Base\Bin\WIN64
   set LD_LIBRARY_PATH=D:\NetExpress\Base\Bin\WIN64;%int%
   set COBDIR=D:\NetExpress\Base\Bin\WIN64;%int%;D:\NetExpress\MFSQL\SOURCE
   set COBDIR64=D:\NetExpress\Base\Bin\WIN64
   set COBPATH=%exe%
   set COBCPY=%int%\LIBRYATM;%int%\LIBRYBOR;%int%\LIBRYBRO;%int%\LIBRYCHG;%int%\LIBRYCTA;%int%\LIBRYDCS;%int%\LIBRYGEN;%int%\LIBRYEN;%int%\LIBRYINV;%int%\LIBRYMIS;%int%\LIBRYSPY;%int%\LIBRYSWI;%int%\LIBRYTRE;%int%\LIBRYUNX;%int%\LIBRYCNV;D:\NetExpress\Base\SOURCE
   set LogFile=%CD%\logfile.log

Assist if possible please...

Julio A.
  • 31
  • 1
  • 1
  • 3

1 Answers1

3

It's as Mathias R. Jessen has mentioned in the comments
You'll have to use the in-built powershell variable $env.
$env has all the environment variables already defined in your system and you can add to them using $env::VariableName = Value
Example would be something like
$env:CLASSPATH = "D:\NetExpress\Base\Bin\WIN64\mfcobol.jar;.;" + $env:CLASSPATH
If setting environment variable is your only goal then this should do it, if you are planning to use these scripts later in the same script file I'd suggest you use powershell variables instead.

Also check out this Microsoft Page for more on Environment Variables and Powershell

23Stinger
  • 56
  • 3
  • What about something like below?: – Julio A. Oct 10 '16 at 12:27
  • {set PATH=D:\NetExpress\Base\Bin\Linker;D:\NetExpress\Base\Bin\WIN64;D:\NetExpress\Base\Bin;D:\NetExpress\PACKAGES\x64;C:\Windows\System32\wbem;C:\Windows\System32\} – Julio A. Oct 10 '16 at 12:28
  • set COBCPY=%int%\LIBRYATM;%int%\LIBRYBOR;%int%\LIBRYBRO;%int%\LIBRYCHG;%int%\LIBRYCTA;%int%\LIBRYDCS;%int%\LIBRYGEN;%int%\LIBRYEN;%int%\LIBRYINV;%int%\LIBRYMIS;%int%\LIBRYSPY;%int%\LIBRYSWI;%int%\LIBRYTRE;%int%\LIBRYUNX;%int%\LIBRYCNV;D:\NetExpress\Base\SOURCE – Julio A. Oct 10 '16 at 12:29
  • @23Stringer - The idea is reference the set paths later in the script so it can be identified to do specific functions based on a path. How would I declare these paths in an instance like that? – Julio A. Oct 10 '16 at 12:31
  • @Julio A. That's good in a batch file not in powershell. To the best of my knowledge Powershell has no 'set' command/command-let. Use `$CLASSPATH= "D:\NetExpress\Base\Bin\WIN64\mfcobol.jar;.;" + $env:CLASSPATH`. You can refer to them later using $CLASSPATH – 23Stinger Oct 10 '16 at 12:38
  • @23Stringer - By referring to $CLASSPATH, all methods, classes and libraries used within the path? – Julio A. Oct 10 '16 at 12:50
  • @Julio A - I'm sorry I don't understand what you mean by 'all methods, classes and libraries within the path'. Are there files/scripts in these path that you want to access through script? If that's the case you can user `$CLASSPATH\ScriptName` or `$CLASSPATH\FileName` else I need some explanation. – 23Stinger Oct 10 '16 at 13:03
  • 1
    PowerShell has both `environment variables` and `script variables`. Environment variables are referenced as from the PSProvider `Env:name`. There is a separate set of script variables which are referenced by `$name`. – lit Oct 10 '16 at 15:39
  • Use `Get-ChildItem Env:` and `Get-ChildItem Variable:` to see the two different lists. – lit Oct 10 '16 at 15:45