0

i'm new to powershell and i don't know lots of things. Script im using atm:

$webfile = "\\mywebserver\prn$\index.html"
$mylog = ("\\mywebserver\prn$\log\monitorprinterqueues_" + (Get-Date).month + (Get-Date).day + (Get-Date).year + ".log")

if ((Test-Path $mylog ) -ne $true) {#check for new log
    $myheader = "datetime*owner*jobstatus*queuestatus*totalpages*size*server*queue*document"
    $myheader| out-file -FilePath $mylog -append -noclobber
}#check for new log

function mystatus ($thisstatus) {
    switch ($thisstatus) {
         "0" { $mytext = "Ok" }
         "1" { $mytext = "Other" }
         "2" { $mytext = "Paused" }
         "3" { $mytext = "Low Paper" }
         "4" { $mytext = "No Paper" }
         "5" { $mytext = "Low Toner" }
         "6" { $mytext = "No Toner" }
         "7" { $mytext = "Door Open" }
         "8" { $mytext = "Paper Jam" }
         "9" { $mytext = "Offline" }
         "10" { $mytext = "Output Bin Full" }
         "11" { $mytext = "Paper Problem" }
         "12" { $mytext = "Cannot Print Page" }
         "13" { $mytext = "User Intervention Required" }
         "14" { $mytext = "Out of Memory" }
         "15" { $mytext = "Server Unknown" }
         default {$mytext = "Error (D)" }
    }
return ($mytext)
}

clear
$myservers = @()
$myservers = ("myprintserver1","myprintserver2")

#exporttoweb
Remove-Item ($webfile)
$head = "<style>"
$head = $head + "BODY{background-color:#9FAEB5;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black;background-color:#999999}"
$head = $head + "TD{border-width: 1px;padding: 4px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$head = $head + "</style>"


foreach ($thisserver in $myservers) {
     $prnstats = gwmi win32_printer -ComputerName $thisserver | %{ $prname = $_.Name; $prtname = $_.portname; $srv = $_.systemname; $status = $_.detectederrorstate; $location = $_.location; gwmi win32_tcpipprinterport -computername $thisserver | where { $_.Name -eq $prtname } | select @{name="Name";expression={$prname}}, @{name="Server";expression={$srv}}, @{name="Status";expression={$status}}, @{name="Location";expression={$location}}, hostaddress }
     $printserver = get-wmiobject "Win32_PrintJob" -computername $thisserver | where { ($_.jobstatus -ne $null) -and ($_.jobstatus -ne "") -and ($_.jobstatus -ne "Printing") -and ($_.jobstatus -ne "Spooling") -and ($_.jobstatus -ne "Spooling | Printing")  }
     if ((Test-Path -Path $webfile) -ne $true) {#writehead top
         $prnstats | select Name, Server, @{name="Status";Expression={mystatus $_.Status }}, Location, @{name="Web-Interface";Expression={$_.hostaddress }} | ConvertTo-HTML -head $head -body "<H2>Printer Status Site</H2>" | Out-File $webfile
     } else {
         $prnstats | select Name, Server, @{name="Status";Expression={mystatus $_.Status }}, Location, @{name="Web-Interface";Expression={$_.hostaddress }} | ConvertTo-HTML | Out-File $webfile -Append
     }
     foreach ($printjob in $printserver) {
         if (($printjob.Jobstatus -ne $null) -and ($printjob.Jobstatus -ne "")){
         switch ($printjob.Jobstatus) {

             default { 
                 $prn = $prnstats | where { $_.name -eq ("" + $printjob.Name.split(',')[0]) }
                 $thisstr = "" + $printjob.TimeSubmitted + "*" + $printjob.Owner + "*" + $printjob.JobStatus + "*" + (mystatus $prn.DetectedErrorState) + "*" + $printjob.TotalPages + "*" + $printjob.Size + "*" + $thisserver + "*" + $printjob.Name + "*" + $printjob.Document
                 $thisstr   | out-file -FilePath $mylog -append -noclobber
                 $printjob.Delete()
             }#end default
         }#end switch
         }#end if
     #$printjob = $null
     }#jobs
    $printserver = $null
    #$printjob = $null
} #servers

The result is html-table html-table. Need to do all the hostnames to be hyperlinks. To be able to get the printer's web-interface asap. How can I do this?

2 Answers 2

2

Change the Web-Interface calculated property expression from

@{name="Web-Interface";Expression={$_.hostaddress }}

to an actual link (<a href='url'>link text</a>)

@{name="Web-Interface";Expression={"<a href='http://{0}/'>{0}</a>" -f $_.hostaddress }}
Sign up to request clarification or add additional context in comments.

1 Comment

Ty, it worked, but now I have another problem. It seems that powershell converts special symbols. And I see just a html code... In html file symbols "<" and ">" at the beginning and the end of anchors converted to "&lt;" and "&gt;" &lt;a href='ATS-Xerox-5675-1.printers.rosenergo.com/'&gt; exept of <a href='ATS-Xerox-5675-1.printers.rosenergo.com'> How can I convert or replace these back to html?
0

Got the solution by adding foreach

ConvertTo-HTML -head $head -body "<H2>Printer Status Site</H2>" | foreach {$_.replace("&lt;","<").replace("&gt;",">")} | Out-File $webfile

Works fine now.

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.