0

I have been given a working PowerShell script to modify. This script checks for broken links in a SharePoint web application and reports any broken links it finds. Currently, the script outputs the results to a text file.

Code:

$results | Out-File report.txt

Result Format:

Name of link list - ID of the item - URL + URL Name - HTTP status code - URL

Result:

Link List 1 - 1 - http://google.com, Google (Good) - 200 - http://google.com


However, when I try to use the ConvertTo-HTML function I get a different output:

Code:

$results | ConvertTo-Html | Out-File report.html

Result:

76

Therefore, instead of receiving a string of text I am receiving its length.

What am I doing wrong here?

Note:

  • results is an array.

1 Answer 1

4

Convertto-Html is not meant to be used like that, from help:

Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser. You need to send an object (resulting from a command) to this cmdlet, not just a bunch of text. See: Get-Help Convertto-Html -Examples

this is a way to do what you want:

$results | ForEach-Object {Add-Member -InputObject $_ -Type NoteProperty -Name Value -Value $_; $_} | ConvertTo-Html -Property Value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.