I’m trying to out put the results of a command to a cmd file but get characters added.
I take the results of mountvol and remove all the lines I don’t want, and modify the results to add text at the front and end of the lines. But it errors as there is a hidden character "more 0<\?".
I’ve tried using the “-Encoding” switch but not had any success. Any suggestions ?
cmd is this
$cmd = $(Join-Path $env:TEMP listVormBind.txt)
Invoke-Command -ScriptBlock { mountvol > $cmd ; (Get-Content $cmd | Where-Object {$_ -match "Volume{" } ).Replace("\\?\","more < \\?\").Replace("}\","}:VormBind").trimstart() } |`
out-file $cmd.replace(".txt",".cmd") -Force
Example of what I get from mountvol
\\?\Volume{b137e4c8-2e49-4ef0-b482-f8f5eef92c36}\
C:\
\\?\Volume{1c5545c9-8c46-4723-a93f-5f43dcb6376b}\
T:\
\\?\Volume{5283dac6-2898-11e9-80c3-4cd98f040d85}\
Q:\
\\?\Volume{75952053-4133-49b1-b503-36c507a7cc96}\
D:\
\\?\Volume{b018b93c-d8c0-46ad-b49e-01ea5335874d}\
D:\MOUNT\Data\
\\?\Volume{0a71066f-81f4-4571-a637-f82624f0d9dd}\
D:\MOUNT\Log\
\\?\Volume{68d8b178-e315-405d-ae5d-91276add6783}\
D:\MOUNT\Backups\
\\?\Volume{247790dc-af4d-4083-b359-461c921c7918}\
G:\
\\?\Volume{bbb284c8-6c64-4a53-8450-1ddf818d687e}\
G:\MOUNT\Data\
\\?\Volume{cac98158-74c8-48e0-b7d3-b56e1a8050ec}\
G:\MOUNT\Log\
\\?\Volume{2a8330d8-5c1b-403c-b445-c892527d2ce4}\
G:\MOUNT\Backups\
Example of what I end up with in the cmd file:
more < \\?\Volume{b137e4c8-2e49-4ef0-b482-f8f5eef92c36}:VormBind
more < \\?\Volume{1c5545c9-8c46-4723-a93f-5f43dcb6376b}:VormBind
more < \\?\Volume{5283dac6-2898-11e9-80c3-4cd98f040d85}:VormBind
more < \\?\Volume{75952053-4133-49b1-b503-36c507a7cc96}:VormBind
more < \\?\Volume{b018b93c-d8c0-46ad-b49e-01ea5335874d}:VormBind
more < \\?\Volume{0a71066f-81f4-4571-a637-f82624f0d9dd}:VormBind
more < \\?\Volume{71390221-655f-4769-a615-45bcc9be4e96}:VormBind
more < \\?\Volume{df4265d7-a07b-4eb0-9bda-8eb732cc1c53}:VormBind
more < \\?\Volume{75bcfab8-9abe-488d-94ef-b26bc9e5d441}:VormBind
but when i run the resulting cmd file, i get an error:
C:\Windows\system32>more 0<\\?\Volume{b137e4c8-2e49-4ef0-b482-f8f5eef92c36}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{1c5545c9-8c46-4723-a93f-5f43dcb6376b}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{5283dac6-2898-11e9-80c3-4cd98f040d85}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{75952053-4133-49b1-b503-36c507a7cc96}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{b018b93c-d8c0-46ad-b49e-01ea5335874d}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{0a71066f-81f4-4571-a637-f82624f0d9dd}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{71390221-655f-4769-a615-45bcc9be4e96}:VormBind
The system cannot find the file specified.
C:\Windows\system32>more 0<\\?\Volume{df4265d7-a07b-4eb0-9bda-8eb732cc1c53}:VormBind
The system cannot find the file specified.