0

I am using the PowerShell Code below which is working fine .

Only part which was not working is the Hyperlink part . Though it is working fine and giving me the output , I could not open the Hyperlink outside the server where I worked on the code .

Not sure how to change the Hyperlink from C:\TEMP\ location and make it dynamically accessible . Kindly suggest .

Code :

$ok = 80
$NotOk = 90

$ser = @('Serv1','Serv2') 
$Out = foreach($s in $ser){
#$Disk = Get-Content C:\temp\Disk.htm

$link =   "<a href='c:\temp\disk.htm'>Disk</a> "


Get-WmiObject Win32_Volume -ComputerName $s|`
Where { $_.drivetype -eq '3' -and $_.driveletter} |`
Select-Object SystemName,driveletter,name,label,
@{Name='freespace';Expression={[Int]($_.freespace/1GB)}},
@{Name='capacity';Expression={[Int]($_.capacity/1GB)}},
@{Name='UsedSpace';Expression={"{0:N0}" -f ( $_.capacity/1GB - $_.FreeSpace/1GB )}},
@{Name='UsedSpacePercent';Expression={"{0:N0}" -f (($_.capacity - $_.FreeSpace) / $_.Capacity * 100)}} | `
Where-Object {$_.label -notlike "Recovery" -and $_.name -notlike "*volume*"  -and $_.name -notlike "D:\" }}

$Out |select SystemName,DriveLetter,Capacity,usedspacepercent|`
convertto-html -Head $Header -Body " <H2 style=color:#000000;font-family:calibri;text-align:left; >Servers Disk Status $link </h2> "|

Out-File C:\Temp\DatabaseStatusReport_Test.html -Append

NOTE : The files which was hyperlinked can be open in the server without any issues .

The hyperlink variable used is $link

Below is the code and error message .

enter image description here

Once I click on Yes I am getting below message

enter image description here

Please help me how can I make it work .

  • So this code is run on a server, then you're trying to open the .htm page from a different server or workstation? – root Apr 4 '18 at 14:01
  • Yes @root , Once send-emailmessage sends to my local id, I am trying to open from my Local Machine . – DBOn Apr 4 '18 at 14:46
  • 1
    @DBOn it tries to open the HTML File on your machine. since it does only exist on the server, you get this errormessage. you can try using a UNC path instead – SimonS Apr 4 '18 at 14:48
  • @DBOn Start with SimonS's comment and send your local machine the full UNC path to the file. Depending on the page's dependencies, consider sending the entire .htm file to the local machine so you can open it locally. – root Apr 4 '18 at 15:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.