title: Save the powershell result output on the user profile that runned the script
body: <p>I have a script that checks, from a defined list, the disk space on our servers.</p>
  
  <p>The initial disk.ps1 and the list.txt file will always be on "D:\scripts\disk.ps1, and I want to send the "result" html file on the Desktop of the user who runned the script.</p>
  
  <p>I'm using the following line, but not sure if OK, did number of tests, but outcome is always an error in powershell.</p>
  
  <pre><code>$Path = "C:\Users\%userprofile%\Desktop\Disk-Report.html"
  </code></pre>
  
  <p>Here is my script :</p>
  
  <pre><code># Simple HTML page displaying disk usage.
  
  Param (
  $computers = (Get-Content  "D:\Scripts\list.txt")
  )
  
  $Title="Hard Drive Report to HTML"
  
  #embed a stylesheet in the html header
  $head = @'
  &lt;style&gt;
  body { background-color:#dddddd;
         font-family:Tahoma;
         font-size:12pt; }
  td, th { border:1px solid black;
           border-collapse:collapse; }
  th { color:white;
       background-color:black; }
  table, tr, td, th { padding: 2px; margin: 0px }
  table { margin-left:50px; }
  &lt;/style&gt;
  
  '@
  
  #define an array for html fragments
  $fragments=@()
  
  #get the drive data
  $data=Get-WmiObject -Class Win32_logicaldisk -filter "drivetype=3" -computer $computers
  
  #group data by computername
  $groups=$Data | Group-Object -Property SystemName
  
  #this is the graph character
  [string]$g=[char]9608 
  
  #create html fragments for each computer
  #iterate through each group object
  
  ForEach ($computer in $groups) {
  
      $fragments+="&lt;H2&gt;$($computer.Name)&lt;/H2&gt;"
  
      #define a collection of drives from the group object
      $Drives=$computer.group
  
      #create an html fragment
      $html=$drives | Select @{Name="Drive";Expression={$_.DeviceID}},
      @{Name="SizeGB";Expression={$_.Size/1GB  -as [int]}},
      @{Name="UsedGB";Expression={"{0:N2}" -f (($_.Size - $_.Freespace)/1GB) }},
      @{Name="FreeGB";Expression={"{0:N2}" -f ($_.FreeSpace/1GB) }},
      @{Name="Usage";Expression={
        $UsedPer= (($_.Size - $_.Freespace)/$_.Size)*100
        $UsedGraph=$g * ($UsedPer/2)
        $FreeGraph=$g* ((100-$UsedPer)/2)
        #I'm using place holders for the &lt; and &gt; characters
        "xopenFont color=Redxclose{0}xopen/FontxclosexopenFont Color=Greenxclose{1}xopen/fontxclose" -f $usedGraph,$FreeGraph
      }} | ConvertTo-Html -Fragment 
  
      #replace the tag place holders. It is a hack but it works.
      $html=$html -replace "xopen","&lt;"
      $html=$html -replace "xclose","&gt;"
  
      #add to fragments
      $Fragments+=$html
  
      #insert a return between each computer
      $fragments+="&lt;br&gt;"
  
  } #foreach computer
  
  #add a footer
  $footer=("&lt;br&gt;&lt;I&gt;Report run {0} by {1}\{2}&lt;I&gt;" -f (Get-Date -displayhint date),$env:userdomain,$env:username)
  $fragments+=$footer
  
  $Path = "C:\Users\%userprofile%\Desktop\Disk-Report.html"
  #write the result to a file
  ConvertTo-Html -head $head -body $fragments  | Out-File -filepath $Path 
  </code></pre>