Advertisement
david62277

PVS Doc Script v2

Apr 3rd, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -Version 4.0
  2. <#
  3. Written by David Ott
  4. This script will document your provisioning server environment, and send it to you via email.  It was developed using PVS 7.12.
  5. Requires powershell version 4 (3 might work) and the PVS module.  More info on the PVS module and commands in the pdf below.
  6. https://docs.citrix.com/content/dam/docs/en-us/provisioning-services/7-12/downloads/PvsSnapInCommands_7_12.pdf
  7. Look for lines marked with #### for important notes, and or areas where you need to edit this script for your environment.
  8. #>
  9. Function Set-AlternatingRows {
  10.     [CmdletBinding()]
  11.         Param(
  12.         [Parameter(Mandatory,ValueFromPipeline)]
  13.         [string]$Line,
  14.        
  15.             [Parameter(Mandatory)]
  16.         [string]$CSSEvenClass,
  17.        
  18.         [Parameter(Mandatory)]
  19.             [string]$CSSOddClass
  20.         )
  21.         Begin {
  22.                 $ClassName = $CSSEvenClass
  23.         }
  24.         Process {
  25.                 If ($Line.Contains("<tr><td>"))
  26.                 {       $Line = $Line.Replace("<tr>","<tr class=""$ClassName"">")
  27.                         If ($ClassName -eq $CSSEvenClass)
  28.                         {       $ClassName = $CSSOddClass
  29.                         }
  30.                         Else
  31.                         {       $ClassName = $CSSEvenClass
  32.                         }
  33.                 }
  34.                 Return $Line
  35.         }
  36. }
  37. $a = @"
  38. <style>
  39. TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;width: 95%}
  40. TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
  41. TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
  42. .odd { background-color:#ffffff; }
  43. .even { background-color:#dddddd; }
  44. </style>
  45. "@
  46. ipmo 'C:\Program Files\Citrix\Provisioning Services Console\Citrix.PVS.SnapIn.dll'
  47. #### stops script if the pvs module is not detected
  48. if (!(gmo).name -contains "Citrix.PVS.Snapin") {
  49. Write-Host "Script requires Citrix.PVS.Snapin"
  50. break
  51. }
  52. $date = Get-Date -F "MM-dd-yyyy_HH-mm-ss"
  53. $smtpserver = "your smtp server here"  #### fqdn or ip address of a smtp server
  54. $emails = "your email here" #### if multiple "email1.company.com","email2.company.com","email3.company.com"
  55. $from = "pvs@report.com" #### from address - usually not important
  56. $subject = "PVS Report $date" #### subject of the email
  57. $PVS = Get-PvsServerInfo | select @{n='PVS Server';e={$_.ServerName}},@{n='Status';e={if ($_.active -eq 1){"Active"} else {"Inactive"}}},@{n='Connected Devices';e={$_.DeviceCount}} | ConvertTo-Html -Head $a -PreContent "<center><h1>PVS Report</h1></center>"| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
  58. $vdisks = Get-PvsDiskInfo  | select @{n="vDisk";e={$_.disklocatorname}},@{n="Active Devices";e={$_.devicecount}},@{n='High Availability';e={$_.haenabled}},@{n="Write Cache Type";e={if ($_.writecachetype -eq "0") {"Private/Maint"} elseif ($_.writecachetype -eq "7") {"Cache to PVS Server Persistent"} elseif ($_.writecachetype -eq "1") {"Cache to PVS Server"}`
  59. elseif ($_.writecachetype -eq "3") {"Cache to Device RAM"} elseif ($_.writecachetype -eq "8") {"Cache to Device Hard Disk Persistent"} elseif ($_.writecachetype -eq "9") {"Cache to RAM with Overflow to Disk"}`
  60. elseif ($_.writecachetype -eq "4") {"Cache on HDD"}}} | ConvertTo-Html | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
  61. $vdiskstart = $vdisks.IndexOf("<table>")
  62. $vdiskend = $vdisks.IndexOf("</table>")
  63. $vdisks = ($vdisks | select -Index ($vdiskstart..$vdiskend))+"<br><br>"
  64. $versions = Get-PvsDiskInfo | select disklocatorid,disklocatorname | %{
  65. $diskname = $_.DiskLocatorName
  66. Get-PvsDiskVersion -DiskLocatorId $_.DiskLocatorId | select @{n='Disk Name';e={$diskname}},Version,@{n="Disk Status";e={if ($_.goodinventorystatus -eq $false -and $_.access -ne "1") {"Not Synced"} elseif ($_.access -ne "1") {"Synced"} elseif ($_.access -eq "1") {"Read/Write"}}}
  67. } | ConvertTo-Html | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
  68. $versionstart = $versions.IndexOf("<table>")
  69. $versionend = $versions.IndexOf("</table>")
  70. $versions = ($versions | select -Index($versionstart..$versionend))+"<br><br>"
  71. $farm = Get-PvsFarm | select @{n='Farm Name';e={$_.FarmName}},@{n='License Server';e={$_.licenseserver}},@{n='Database Server Name';e={$_.databaseservername}},`
  72. @{n='Database Name';e={$_.databasename}},@{n='Offline DB Enabled';e={$_.offlinedatabasesupportenabled}} | ConvertTo-Html | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
  73. $farmstart = $farm.IndexOf("<table>")
  74. $farmend = $farm.IndexOf("</table>")
  75. $farm = $farm | select -Index($farmstart..$farmend)
  76. $join = $vdisks+$versions+$farm
  77. $insert = $pvs.IndexOf("</table>")-1
  78. $message = ($pvs -split "\<\/table\>")[0..$insert]+"</table>"+"<br><br>"+$join+"</body></html>"
  79. Send-MailMessage -From $from -To $emails -Subject $subject -Body "$message" -BodyAsHtml -SmtpServer $smtpserver #### sends the report in an email
  80. #### And/or uncommment the line below, and adjust the path to create an html file
  81. #$message | Out-File \\server\share\pvs_report_$date.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement