# results of Out-File has extra characters

**URL:** <https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951>\
**Category:** PowerShell Help\
**Created:** [July 31, 2019, 9:47am UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951 "2019-07-31T09:47:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)\
**Post date:** [July 31, 2019, 9:47am UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/1 "2019-07-31T09:47:58Z")

</div>

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 ?

&nbsp;

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.
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [July 31, 2019, 11:47am UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/2 "2019-07-31T11:47:28Z")

</div>

you can try without saving it to a file.

```
(mountvol | Where-Object {$_ -match "Volume{" } ).Replace("\\?\","more < \\?\").Replace("}\","}:VormBind").trimstart()
```

I don’t know why you are using Invoke-Command here, you can execute it without using invoke command.

---

<div class="post-metadata">

**Author:** ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)\
**Post date:** [July 31, 2019, 11:58am UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/3 "2019-07-31T11:58:45Z")

</div>

Because I’m going to be executing it on 4 servers remotely…just testing it locally right now.

---

<div class="post-metadata">

**Author:** ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)\
**Post date:** [July 31, 2019, 12:01pm UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/4 "2019-07-31T12:01:39Z")

</div>

btw the results are the same, using just the simple local command.

I get this:

```
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
more < \\?\Volume{68d8b178-e315-405d-ae5d-91276add6783}:VormBind
more < \\?\Volume{7bed7244-3209-4569-a4f3-ba42bc976d53}:VormBind
more < \\?\Volume{247790dc-af4d-4083-b359-461c921c7918}:VormBind
more < \\?\Volume{bbb284c8-6c64-4a53-8450-1ddf818d687e}:VormBind
more < \\?\Volume{cac98158-74c8-48e0-b7d3-b56e1a8050ec}:VormBind
more < \\?\Volume{2a8330d8-5c1b-403c-b445-c892527d2ce4}:VormBind
more < \\?\Volume{66cc3ba5-9d4f-45ca-8eb1-787d22b72d3c}:VormBind
more < \\?\Volume{52e14aec-9d7f-4173-ad27-f59f157fb27c}:VormBind
more < \\?\Volume{6d305ccf-8a01-432b-964d-f1a404c47437}:VormBind
more < \\?\Volume{bac4c5e0-6386-4027-a762-d17ef0c90943}:VormBind
more < \\?\Volume{ec492462-2f39-497f-a80a-8b6edacf0f64}:VormBind
more < \\?\Volume{8586bade-298d-11e9-80c6-f8f21e3cff41}:VormBind
more < \\?\Volume{f94a5596-afe6-11e9-80d3-f8f21e3cff40}:VormBind
```

If I run one of those commands, i get

```
C:\Windows\system32>more < \\?\Volume{b018b93c-d8c0-46ad-b49e-01ea5335874d}:VormBind
The system cannot find the file specified.
```

If I output to a cmd file and run the resulting cmd file, i get this:

```
C:\Windows\system32>■m
'■m' is not recognized as an internal or external command,
operable program or batch file.
```

---

<div class="post-metadata">

**Author:** ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)\
**Post date:** [July 31, 2019, 1:55pm UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/5 "2019-07-31T13:55:15Z")

</div>

Problem solved. The instructions I’d been given by Vormetric were in correct and was missing a .

This

```
Replace("}\","}:VormBind")
```

Should be this

```
Replace("}\","}\:VormBind")
```

---

<div class="post-metadata">

**Author:** ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)\
**Post date:** [August 1, 2019, 5:19am UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/6 "2019-08-01T05:19:07Z")

</div>

Final script that works:

```
$cmd = $(Join-Path $env:TEMP listVormBind.txt)
$Listvormbind = $cmd.replace(".txt",".cmd")
mountvol > $cmd ; (Get-Content $cmd | Where-Object {$_ -match "Volume{" } ).Replace("\\?\","more < \\?\").Replace("}\","}\:VormBind").trimstart() |`
out-file $Listvormbind -Force -Encoding utf8
$command = @'
cmd.exe /C $Listvormbind
'@
Invoke-Expression -Command:$command
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/results-of-out-file-has-extra-characters/12951/7 "2024-05-16T20:31:50Z")

</div>


