Another post for me that is simple and hopefully serves as an example for people trying to get blogging as a quick archive of SQL Saturday data last week, and while doing that, I had some issues building the HTML needed in PowerShell. I decided to work through this a bit and determine what was wrong.
My original code looked like this:
$folder = "E:DocumentsgitSQLSatArchiveSQLSatArchiveSQLSatArchiveClientApppublicAssetsPDF"
$code = ""
$list = Get-ChildItem -Path $folder
ForEach ($File in $list) {
#write-host($File.name)
$code = $code + "<li><a href=$($File.Name)>$($File.BaseName)</a></li>"
}
write-host($code)This gave me the code I needed, which I then edited in SSMS to get the proper formatting. However, I knew this needed to work.
I
had used single quotes and then added in the slashes, but that didn’t work. This code:
$folder = "E:DocumentsgitSQLSatArchiveSQLSatArchiveSQLSatArchiveClientApppublicAssetsPDF"
$code = ""
$list = Get-ChildItem -Path $folder
ForEach ($File in $list) {
#write-host($File.name)
$code = $code + '<li><a href="/Assets/PDF/$($File.Name)" >$($File.BaseName)</a></li>'
}
write-host($code)produced this type of output:
<li><a href="/Assets/PDF/$($File.Name)" >$($File.BaseName)</a></li>
Not exactly top notch HTML.
I decided that I should look around. I found a post on View comments in original post (opens in new tab)