Echo %path% on separate lines - powershell

Using the Windows command prompt, can I echo %path% and get the resulting paths on separate rows?
Something like this, but for Windows:
echo $PATH | tr ':' '\n'
Can I do this with vanilla cmd or do I need PowerShell or JavaScript scripting?
Example echo %path% output:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;
Desired output:
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;

Try:
($env:Path).Replace(';',"`n")
or
$env:path.split(";")

Fewer keystrokes using either the split operator or method
$env:Path -split ';'
$env:Path.split(';')

This works for me (in a cmd window):
powershell -Command ($env:Path).split(';')

Related

Issues calling a Batch File through PowerShell

I'm having some issues when trying to call a batch file through PowerShell. When I run the batch file itsel, everything works fine; below is my PS Code
cmd.exe /c "C:\Source\BuildSource\SATCOM\EBEM\LCT GUI 02.01.04\run_ebem_lct_020104.bat"
Below is my batch file
#title EBEM LCT 02.01.04
PathTemp=%Path%
# Path=C:\Program Files\jre7\bin;%Path%
Path=C:\Program Files\jre7\bin;%Path%
start javaw -classpath .\EBEM_LCT_020104.jar;comm.jar ebem_lct.system.LCT_Client Path=%PathTemp% PathTemp= exit
and finally, below is what PS is spitting back to me
C:\Users\localadmin\Desktop\PowerShell>PathTemp=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\HID Global\ActivClient\;C:\Program Files\HID Global\ActivClient\;C:\Program Files\Tumbleweed\Desktop Validator\;C:\Program Files\Tumbleweed\Desktop Validator\x86;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\usr\bin;C:\Program Files\PuTTY\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\dotnet\;C:\Users\localadmin\AppData\Local\Microsoft\WindowsApps;C:\Source\TDC-Certs\TDC-Certs\OpenSSL-Win64\bin;C:\Users\localadmin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\localadmin\.dotnet\tools
'PathTemp' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\localadmin\Desktop\PowerShell># Path=C:\Program Files\jre7\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\HID Global\ActivClient\;C:\Program Files\HID Global\ActivClient\;C:\Program Files\Tumbleweed\Desktop Validator\;C:\Program Files\Tumbleweed\Desktop Validator\x86;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\usr\bin;C:\Program Files\PuTTY\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\dotnet\;C:\Users\localadmin\AppData\Local\Microsoft\WindowsApps;C:\Source\TDC-Certs\TDC-Certs\OpenSSL-Win64\bin;C:\Users\localadmin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\localadmin\.dotnet\tools
'#' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\localadmin\Desktop\PowerShell>Path=C:\Program Files\jre7\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\HID Global\ActivClient\;C:\Program Files\HID Global\ActivClient\;C:\Program Files\Tumbleweed\Desktop Validator\;C:\Program Files\Tumbleweed\Desktop Validator\x86;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\usr\bin;C:\Program Files\PuTTY\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\dotnet\;C:\Users\localadmin\AppData\Local\Microsoft\WindowsApps;C:\Source\TDC-Certs\TDC-Certs\OpenSSL-Win64\bin;C:\Users\localadmin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\localadmin\.dotnet\tools
No need to use cmd /c to invoke a batch file from PowerShell; just invoke it directly, which in the case of a quoted batch-file path requires use of &, the call operator.
Your batch file:
is missing #echo off to suppress echoing the commands before they're being executed
mistakenly tries to set environment variables without the SET command
mistakenly tries to use # to initiate a line comment.
In general, it looks like the code was copied from a Bash shell script and poorly adapted for cmd.exe.
Invocation from PowerShell:
& "C:\Source\BuildSource\SATCOM\EBEM\LCT GUI 02.01.04\run_ebem_lct_020104.bat"
Fixed batch-file content:
#echo off
setlocal
:: Set the window title - this will revert when the batch file exits,
:: so there is little point in doing this, given that `start` below
:: launches the application *asynchronously* and the batch file therefore
:: exits quickly.
title EBEM LCT 02.01.04
:: Temporarily add a folder to the PATH.
:: Thanks to `setlocal`, there is no need to restore the previous path afterwards.
Set "Path=C:\Program Files\jre7\bin;%Path%"
:: Start the application
start javaw -classpath .\EBEM_LCT_020104.jar;comm.jar ebem_lct.system.LCT_Client
The alternative is to make do without a batch file altogether, and do it all in PowerShell:
# Save the previous $env:Path value and temporarily prepend a new folder.
$prevPath, $env:Path = $env:Path, "C:\Program Files\jre7\bin;$env:Path"
# Invoke the (GUI) application, which launches asynchronously.
javaw -classpath .\EBEM_LCT_020104.jar;comm.jar ebem_lct.system.LCT_Client
# Restore the original $env:Path value.
$env:Path = $prevPath

What is the right syntax for launching an executable in Appveyor?

I'm trying to start the Azure Storage Emulator in an AppVeyor instance but I can't find the right syntax. I've tried this:
- ps: "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
and this:
- ps: & "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
and this:
- "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
All fail with various unhelpful YAML parsing errors.
- cmd: '"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
or simple:
- '"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
or with PowerShell:
- ps: '& "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
Easiest way to avoid YAML parsing errors is to do initial configuration in UI and then press Export YAML. GitHub search for appveyor.yml <something> often brings useful results too.

PowerShell doesn't recognize basic cmdlets

When calling basic cmdlets in PowerShell 3.0, PowerShell does not recognize them:
Write-Host "Test"
# returns error "The term 'Write-Host' is not recognized as the name of a
# cmdlet, function, (etc.)
The same holds true for many other basic PowerShell scripts.
$Env.Path is set to:
C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Program
Files\Microsoft Office Servers\15.0\Bin\; c:\Program Files
(x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;
c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;
c:\Program Files\Microsoft SQL Server\110\Tools\Binn\; c:\Program
Files (x86)\Microsoft SQL Server\110\DTS\Binn\; C:\Program
Files\Microsoft SQL Server\110\DTS\Binn\; C:\Program Files\Microsoft
SQL Server\Client SDK\ODBC\110\Tools\Binn\; C:\Program Files
(x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\; C:\Program
Files (x86)\Microsoft SQL Server\120\DTS\Binn\; C:\Program
Files\Microsoft SQL Server\120\DTS\Binn\
$Env.PSModulePath displays:
C:\Users\{username}\Documents\WindowsPowerShell\Modules;;C:\Program
Files\AppFabric 1.1 for Windows Server\PowershellModules;C:\Program
Files\AppFabric 1.1 for Windows Server\PowershellModules;C:\Program
Files (x86)\Microsoft SQL
Server\110\Tools\PowerShell\Modules\;C:\Program Files (x86)\Microsoft
SQL Server\120\Tools\PowerShell\Modules\

The term 'xsd' is not recognized as the name of a cmdlet, function, script file, or operable program

When executing the following script (this is a part of the actual script), I'm getting the following error message in powershell:
The term 'xsd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:10 char:3
$xsds = ls *.xsd | %{ $_.Name }
if ($xsds.Count -eq 0) { exit }
# Add '.\' to last file name, see http://stackoverflow.com/questions/906093/xsd-exe-output-filename
$last = $xsds | select -last 1
$last = '.\' + $last
$xsds[$xsds.Count - 1] = $last
& xsd $xsds /c /n:OutputFolder
Are there some requirements for Powershell that I need to install to be able to run the 'xsd' cmdlet first?
The output of $env:Path:
PS C:\Users\Administrator\Desktop\New> $env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Mi
crosoft\Web Platform Installer\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files
(x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Micro
soft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program F
iles (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
PS C:\Users\Administrator\Desktop\New>
An xsd.exe is available in the folders:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64
The paths you have listed are not part of your PATH environment variable. So that leaves you with two options. Add the directories to path or just reference the exe by its full path.
& "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe" $xsds /c /n:OutputFolder
If you want to change your paths you could update them like this
$env:Path += ";C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools"
If you need x64 paths just update the strings.

CSPack and CSRun for running site in azure emulator from powershell

I have spend some time trying to get the cspack and csrun command working to run a website locally in the azure emulator.
So far this is what I get, but its not working
I use psake
Task StartAzureEmulator {
& 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\cspack' sitename.azure\ServiceDefinition.csdef /out:Sitename.csx /role:sitename;sitename /sites:Vola;Web;Web /copyOnly
& 'C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun' sitename.csx sitename.Azure\ServiceConfiguration.Local.cscfg /useiisexpress /launchbrowser
}
Basically I am not very impressed with how the azure commandline tools works with powershell.
Has anyone got example of this working?
In PowerShell the ; character is a statement separator. You can escape it by preceding it with a backtick or if you are V3 or higher you can user --% to switch PowerShell into a simpler (dumber) parser mode. Try this:
Task StartAzureEmulator {
& 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\cspack' --% sitename.azure\ServiceDefinition.csdef /out:Sitename.csx /role:sitename;sitename /sites:Vola;Web;Web /copyOnly
& 'C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun' --% sitename.csx sitename.Azure\ServiceConfiguration.Local.cscfg /useiisexpress /launchbrowser
}