Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-AsBuiltReport : Exception calling "Save" with "1" argument(s): "'.', hexadecimal value 0x00, is an invalid character." #26

Open
3 tasks done
Tony-SouthFLVMUG opened this issue Apr 4, 2024 · 9 comments · Fixed by #27
Assignees
Labels
wontfix This will not be worked on

Comments

@Tony-SouthFLVMUG
Copy link

Bug description

When running the report against a 2012R2 server I am receiving this error upon completion. New-AsBuiltReport : Exception calling "Save" with "1" argument(s): "'.', hexadecimal value 0x00, is an invalid character." The Word file is created however it is zero bytes. I have been able to successfully run it on the same machine against another target (albiet 2016) and it works flawlessly.

Command-line input

New-AsBuiltReport -Report Microsoft.Windows -Target '2012.domain.com' -Format Word -OutputFolderPath 'C:\Reports\Report' -ReportConfigFilePath 'C:\Reports\Config\Microsoft.Windows.json' -Verbose -Filename '2024-04-03 - Windows As Built'

Steps to reproduce

  1. Ran Powershell script

Expected behaviour

Word file creation

Screenshots

No response

Operating System

Server 2019

PowerShell Version

PS C:\Windows\system32> $PSVersionTable

Name Value


PSVersion 5.1.17763.5576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PowerShell Modules

Name Version


AsBuiltReport.Core 1.4.0
AsBuiltReport.Microsoft.Windows 0.5.3
PScribo 0.10.0

Additional Context

No response

Before submitting

@Tony-SouthFLVMUG Tony-SouthFLVMUG added the bug Something isn't working label Apr 4, 2024
@rebelinux
Copy link
Collaborator

I saw that you ran the script with verbose enabled, can you send me the complete log?

if it is not possible maybe you can search if there is any other error message in the log

@rebelinux rebelinux added this to the v0.5.4 milestone Apr 4, 2024
@Tony-SouthFLVMUG
Copy link
Author

Tony-SouthFLVMUG commented Apr 5, 2024

Jonathan below is the output. I did look it over before opening this bug report. I am able to get this to work fine on the 2016 & 2019 servers in the customers environment, however 2012 & 2012R2 all give me this error. Additionally, I am getting the error when running the Active Directory module as well.

VERBOSE: Saving As Built Report configuration file 'AsBuiltReport.json' to path 'C:\Reports\Config'.
VERBOSE: Config.Report.Author = Tony Gonzalez
VERBOSE: Config.UserFolder.Path =
VERBOSE: Config.Company.FullName = customer
VERBOSE: Config.Company.Contact =
VERBOSE: Config.Company.Phone =
VERBOSE: Config.Company.Email =
VERBOSE: Config.Company.ShortName =
VERBOSE: Config.Company.Address =
VERBOSE: Config.Email.Port =
VERBOSE: Config.Email.Credentials =
VERBOSE: Config.Email.Server =
VERBOSE: Config.Email.To =
VERBOSE: Config.Email.From =
VERBOSE: Config.Email.UseSSL =
VERBOSE: Config.Email.Body =
VERBOSE: Populating RepositorySourceLocation property for module AsBuiltReport.Core.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\AsBuiltReport.Core\1.4.0\AsBuiltReport.Core.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module AsBuiltReport.Microsoft.Windows.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\AsBuiltReport.Microsoft.Windows\0.5.3\AsBuiltReport.Microsoft.Windows.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\AsBuiltReport.Microsoft.Windows\AsBuiltReport.Microsoft.Windows.psm1'.
VERBOSE: Loading AsBuiltReport.Microsoft.Windows report configuration file from path 'C:\Reports\Config\Microsoft.Windows.json'.
VERBOSE: Setting report filename to '2024-04-03 - customer - Server2012 - Windows As Built'.
VERBOSE: Populating RepositorySourceLocation property for module AsBuiltReport.Core.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\AsBuiltReport.Core\1.4.0\AsBuiltReport.Core.psm1'.
WARNING: [ 07:42:31:720 ] [ Module ] - AsBuiltReport.Core 1.4.0 is currently installed.
VERBOSE: [ 07:42:36:970 ] [ Document ] - Document '2024-04-03 - customer - Server2012 - Windows As Built' processing started.
VERBOSE: [ 07:42:37:564 ] [ Document ] - Please wait while the Microsoft Windows As Built Report is being generated.
VERBOSE: [ 07:42:37:564 ] [ Document ] - Executing report style script from path 'C:\Program Files\WindowsPowerShell\Modules\AsBuiltReport.Microsoft.Windows\0.5.3\AsBuiltReport.Microsoft.Windows.Style.ps1'.
VERBOSE: [ 07:42:39:377 ] [ Document ] - Setting global document options.
VERBOSE: [ 07:42:39:392 ] [ Document ] - Enabling section/heading numbering.
VERBOSE: [ 07:42:39:392 ] [ Document ] - Setting default font(s) to 'Segoe Ui'.
VERBOSE: [ 07:42:39:392 ] [ Document ] - Setting page top margin to '25.05'mm.
VERBOSE: [ 07:42:39:408 ] [ Document ] - Setting page right margin to '25.05'mm.
VERBOSE: [ 07:42:39:408 ] [ Document ] - Setting page bottom margin to '25.05'mm.
VERBOSE: [ 07:42:39:408 ] [ Document ] - Setting page left margin to '25.05'mm.
VERBOSE: [ 07:42:39:424 ] [ Document ] - Setting page size to 'A4'.
VERBOSE: [ 07:42:39:424 ] [ Document ] - Setting page orientation to 'Portrait'.
VERBOSE: [ 07:42:39:424 ] [ Document ] - Setting page height to '297'mm.
VERBOSE: [ 07:42:39:439 ] [ Document ] - Setting page width to '210'mm.
VERBOSE: [ 07:42:39:439 ] [ Document ] - Setting document style 'Title'.
VERBOSE: [ 07:42:39:455 ] [ Document ] - Setting document style 'Title2'.
VERBOSE: [ 07:42:39:470 ] [ Document ] - Setting document style 'Title3'.
VERBOSE: [ 07:42:39:470 ] [ Document ] - Setting document style 'Heading1'.
VERBOSE: [ 07:42:39:502 ] [ Document ] - Setting document style 'Heading2'.
VERBOSE: [ 07:42:39:517 ] [ Document ] - Setting document style 'Heading3'.
VERBOSE: [ 07:42:39:517 ] [ Document ] - Setting document style 'NOTOCHeading3'.
VERBOSE: [ 07:42:39:533 ] [ Document ] - Setting document style 'Heading4'.
VERBOSE: [ 07:42:39:533 ] [ Document ] - Setting document style 'NOTOCHeading4'.
VERBOSE: [ 07:42:39:549 ] [ Document ] - Setting document style 'Heading5'.
VERBOSE: [ 07:42:39:564 ] [ Document ] - Setting document style 'NOTOCHeading5'.
VERBOSE: [ 07:42:39:564 ] [ Document ] - Setting document style 'Heading6'.
VERBOSE: [ 07:42:39:580 ] [ Document ] - Setting document style 'NOTOCHeading6'.
VERBOSE: [ 07:42:39:580 ] [ Document ] - Setting document style 'NOTOCHeading7'.
VERBOSE: [ 07:42:39:595 ] [ Document ] - Setting document style 'Normal'.
VERBOSE: [ 07:42:39:595 ] [ Document ] - Setting document style 'Caption'.
VERBOSE: [ 07:42:39:611 ] [ Document ] - Setting document style 'Header'.
VERBOSE: [ 07:42:39:611 ] [ Document ] - Setting document style 'Footer'.
VERBOSE: [ 07:42:39:627 ] [ Document ] - Setting document style 'TOC'.
VERBOSE: [ 07:42:39:627 ] [ Document ] - Setting document style 'TableDefaultHeading'.
VERBOSE: [ 07:42:39:642 ] [ Document ] - Setting document style 'TableDefaultRow'.
VERBOSE: [ 07:42:39:658 ] [ Document ] - Setting document style 'Critical'.
VERBOSE: [ 07:42:39:674 ] [ Document ] - Setting document style 'Warning'.
VERBOSE: [ 07:42:39:689 ] [ Document ] - Setting document style 'Info'.
VERBOSE: [ 07:42:39:705 ] [ Document ] - Setting document style 'OK'.
VERBOSE: [ 07:42:39:720 ] [ Document ] - Setting table style 'TableDefault'.
VERBOSE: [ 07:42:39:720 ] [ Document ] - Setting table style 'Borderless'.
VERBOSE: [ 07:42:39:783 ] [ Document ] - Processing document header started.
VERBOSE: [ 07:42:39:861 ] [ Document ] - Processing paragraph 'Microsoft Windows As Built Report - v1.0'.
VERBOSE: [ 07:42:40:033 ] [ Document ] - Processing document header completed.
VERBOSE: [ 07:42:40:064 ] [ Document ] - Processing document footer started.
VERBOSE: [ 07:42:40:080 ] [ Document ] - Processing paragraph 'Page <!# PageNumber #!>'.
VERBOSE: [ 07:42:40:095 ] [ Document ] - Processing document footer completed.
VERBOSE: [ 07:42:40:127 ] [ Document ] - Processing blank line.
VERBOSE: [ 07:42:40:189 ] [ Document ] - Processing image 'AsBuiltReport Logo'.
VERBOSE: [ 07:42:40:533 ] [ Document ] - Processing blank line.
VERBOSE: [ 07:42:40:549 ] [ Document ] - Processing paragraph 'Microsoft Windows As Built Report'.
VERBOSE: [ 07:42:40:549 ] [ Document ] - Processing blank line.
VERBOSE: [ 07:42:40:564 ] [ Document ] - Processing paragraph 'customer'.
VERBOSE: [ 07:42:40:564 ] [ Document ] - Processing blank line.
VERBOSE: [ 07:42:40:658 ] [ Document ] - Processing table 'Cover Page'.
VERBOSE: [ 07:42:40:752 ] [ Document ] - Processing page break.
VERBOSE: [ 07:42:40:783 ] [ Document ] - Processing table of contents 'Table of Contents'.
VERBOSE: [ 07:42:40:783 ] [ Document ] - Processing page break.
VERBOSE: Populating RepositorySourceLocation property for module dbatools.
VERBOSE: [ 07:56:37:752 ] [ Document ] - Processing table 'Zones - Server2012'.
VERBOSE: [ 07:56:37:767 ] [ Document ] - Processing section 'Reverse Lookup Zone Configuration' completed.
VERBOSE: [ 07:56:37:814 ] [ Document ] - Processing section 'DNS Zone Configuration' completed.
VERBOSE: [ 07:56:37:830 ] [ Document ] - Processing section 'DNS Server Configuration' completed.
VERBOSE: [ 07:56:37:877 ] [ Document ] - No FailOver Cluster service detected. Disabling FailOver Cluster section
VERBOSE: [ 07:56:37:939 ] [ Document ] - No SQL Server service detected. Disabling SQL Server section
VERBOSE: [ 07:56:37:955 ] [ Document ] - Processing section 'Server2012' completed.
VERBOSE: [ 07:56:38:252 ] [ Document ] - Document '2024-04-03 - customer - Server2012 - Windows As Built' processing completed.
VERBOSE: [ 07:56:38:283 ] [ Document ] - Total processing time '14.02' minutes.
New-AsBuiltReport : Exception calling "Save" with "1" argument(s): "'.', hexadecimal value 0x00, is an invalid character."
At line:1 char:1

  • New-AsBuiltReport -Report Microsoft.Windows -Target 'Server2012' -Userna ...
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-AsBuiltReport
    

@rebelinux
Copy link
Collaborator

Hi Tony,

Thanks for the log. I believe the error is on the AsBuiltReport.Core side. Can your run the report again but this time with the verbose/debug option set globally so i can troubleshoot the AsBuiltReport.Core module.

$global:VerbosePreference = 'Continue'
$global:DebugPreference = 'Continue'
Start-Transcript -Path .\Output.log
New-AsBuiltReport <-- your command here
Stop-Transcript

Remember to set its value to the default one after generating the log!

$global:VerbosePreference = 'SilentlyContinue'
$global:DebugPreference = 'SilentlyContinue'

The output.log can be attached here or if privacy is a concern you can send it to me at: [email protected]

@rebelinux
Copy link
Collaborator

rebelinux commented Apr 5, 2024

Looking into the log the script is failing at the Out-WordDocument cmdlet.

Can you re-run the report with the -Format HTML so I can rule out if the problem is just in the Word document format generation?

VERBOSE: [ 13:34:55:586 ] [   Word   ] - Processing document part '/word/document.xml'.
VERBOSE: [ 13:34:55:601 ] [   Word   ] - Writing document part '/word/document.xml'.
PS C:\Windows\system32> TerminatingError(Out-WordDocument): "Exception calling "Save" with "1" argument(s): "'.', hexadecimal value 0x00, is an invalid character.""
>> TerminatingError(Out-WordDocument): "Exception calling "Save" with "1" argument(s): "'.', hexadecimal value 0x00, is an invalid character.""

Also can you share with us the $OutputEncoding results from both the 2012 r2 server and the machine used to generate the report?

I did a test with a 2012 r2 server on my HomeLab and was able to generate the report with no problem.

I suspect it may be a problem with the character encoding. I have had strange problems with that when using languages or encoding other than En-US.

rebelinux added a commit to rebelinux/AsBuiltReport.Microsoft.Windows that referenced this issue Apr 7, 2024
….', hexadecimal value 0x00, is an invalid character." AsBuiltReport#26
rebelinux added a commit to rebelinux/AsBuiltReport.Microsoft.Windows that referenced this issue Apr 7, 2024
….', hexadecimal value 0x00, is an invalid character." AsBuiltReport#26
@rebelinux
Copy link
Collaborator

rebelinux commented Apr 8, 2024

Hi:

I found the issue, it was difficult to diagnose but easy to fix....

if you want to test the solution before the next version is released just change the following line:

File Src/Private/Get-AbrWinHostStorageVolume.ps1 at line 30:

# From:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $NUll -ne $_.DriveLetter} }
# To:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $_.DriveLetter} }

After saving the changes to the files don't forget to import the module:

Import-Module AsBuiltReport.Microsoft.Windows -Force

@rebelinux rebelinux mentioned this issue Apr 8, 2024
7 tasks
@rebelinux rebelinux reopened this Apr 8, 2024
@rebelinux rebelinux mentioned this issue May 16, 2024
7 tasks
@rebelinux
Copy link
Collaborator

After some time researching this issue I am unable to identify where the problem lies. At first I thought that the problem was related to the Pscribo module but now I am convinced that it is a problem with the powershell version of windows 2012/2012R2.

@rebelinux rebelinux added wontfix This will not be worked on and removed bug Something isn't working labels May 26, 2024
@rebelinux rebelinux reopened this May 27, 2024
@rebelinux
Copy link
Collaborator

I will leave the issue open so that other users with the same problem can identify that the issue is not fixable.

@rebelinux rebelinux removed this from the v0.5.4 milestone May 27, 2024
@flynngw
Copy link
Contributor

flynngw commented Jul 18, 2024

Hi:

I found the issue, it was difficult to diagnose but easy to fix....

if you want to test the solution before the next version is released just change the following line:

File Src/Private/Get-AbrWinHostStorageVolume.ps1 at line 30:

# From:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $NUll -ne $_.DriveLetter} }
# To:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $_.DriveLetter} }

After saving the changes to the files don't forget to import the module:

Import-Module AsBuiltReport.Microsoft.Windows -Force

I have encountered this issue, and in this instance, the above is indeed the fix.
We are getting all drives, even those without a drive letter. Somewhere in the mix, a "0x0" is being added for the drive letter of that disk.
The issue is caused because the "XML" body of the word document contains invalid characters
When PSCribo tries to save the XML we have in memory to an "open-xml formatted word document", it fails, as it contains an invalid character.
If you were to cleanse invalid characters from the xml output prior to trying to save it, that should resolve this issue for any module.

@rebelinux
Copy link
Collaborator

rebelinux commented Jul 18, 2024

Hi:
I found the issue, it was difficult to diagnose but easy to fix....
if you want to test the solution before the next version is released just change the following line:
File Src/Private/Get-AbrWinHostStorageVolume.ps1 at line 30:

# From:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $NUll -ne $_.DriveLetter} }
# To:
$HostVolumes = Invoke-Command -Session $TempPssSession -ScriptBlock {  Get-Volume | Where-Object {$_.DriveType -ne "CD-ROM" -and $_.DriveLetter} }

After saving the changes to the files don't forget to import the module:
Import-Module AsBuiltReport.Microsoft.Windows -Force

I have encountered this issue, and in this instance, the above is indeed the fix. We are getting all drives, even those without a drive letter. Somewhere in the mix, a "0x0" is being added for the drive letter of that disk. The issue is caused because the "XML" body of the word document contains invalid characters When PSCribo tries to save the XML we have in memory to an "open-xml formatted word document", it fails, as it contains an invalid character. If you were to cleanse invalid characters from the xml output prior to trying to save it, that should resolve this issue for any module.

The problem is that I don't own the PScribo code and I can't find a way to reproduce the error that will allow me to create an issue in the PScribo repository.

If you have a way to reproduce the error and explain it well, would it be possible for you to create an issue in the PScribo repository?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants