Using Powershell command to send output to text file outputs word wrapped text?

Viewed 77

In a Windows shell script, I'm running

for /f "usebackq tokens=1* delims=:" %%a in (`powershell "get-physicaldisk | format-list"`) do echo %%a %%b

The very first line it encounters is:

ObjectId                     : {1}\\ERNIE-WIN10PRO\root/Microsoft/Windows/Storage/Provi
                               ders_v2\SPACES_PhysicalDisk.ObjectId="{b8c6f511-2d7d-11
                               ec-971a-806e6f6e6963}:PD:{b02a7c27-2f8e-743f-233c-f60a0
                               a1ce840}"

It echoes %%a as "ObjectId" but it cuts off %%b exactly as shown above...

{1}\ERNIE-WIN10PRO\root/Microsoft/Windows/Storage/Provi

If I stretch the CMD window so that it cuts off (e.g.) after "SPACES", then that's where %%b gets cut off. Not only is this a problem as far as getting the full %%b value, but it causes the next line to fail with

ders was not expected at this time.

This seems like such odd behavior. Why on earth is it happening and how do I fix it?

0 Answers
Related