Skip to content
Permalink
Browse files

Upload Horizon Scripts

Initial Password/Usage Scripts
  • Loading branch information...
dpaluszek committed Jul 19, 2018
1 parent 44557a6 commit 364727ce38d067bf55eed2573f3b2bd107247644
Showing with 53 additions and 0 deletions.
  1. +8 −0 horizon-password.ps1
  2. +45 −0 horizon-usage-script.ps1
@@ -0,0 +1,8 @@
###Horizon Usage for VMware Cloud Provider Program
###Version 1.0 - 19July2018 - Daniel Paluszek / Winston Blake
###This part will prompt for the service account credentials and store them in a secure string text file.

$filename=read-host -Prompt "What should the name of the file be? (will be a .txt file)"

#Replace "C:\directory\" with the target directory for your secure string text file.
read-host -AsSecureString -prompt "Please enter the password" | ConvertFrom-SecureString | Out-File C:\horizon\$filename.txt
@@ -0,0 +1,45 @@
###Horizon Usage for VMware Cloud Provider Program
###Version 1.0 - 19July2018 - Daniel Paluszek, VMware Cloud Provider Program
###Part 2 of 2 - this Powershell script will get the password secure string file, connect to the Horizon Manager and retrieve the usage stats to a file & email.
###For usage of stored credentials, the same user account that runs this script must have generated the stored encrypted password in the accompanying text file.

##ConnectHVServer variables
##Replace "C:\DIRECTORY\file.txt" with the path to your encrypted service account password
$password = get-content C:\horizon\file.txt | ConvertTo-SecureString

##Replace "DOMAIN\username" with service account name previously used in Part 1 of 2
$credentials = new-object -TypeName System.Management.Automation.PSCredential -argumentlist "CORP\horizonsvc",$password

##Replace FQDN with hostname of your Horizon Manager server.
$hznode ="view-01a.corp.local"

##Import the Horizon Module
import-module VMware.VimAutomation.HorizonView

##Connect to the connection server
connect-hvserver -Credential $credentials -Server $hznode

##variable for navigating API Extension Data
$hzservices=$Global:DefaultHVServers.ExtensionData

##variable for storing connection server health metrics (contains data we're after)
$hzhealth=$hzservices.ConnectionServerHealth.ConnectionServerHealth_List()

##Replace "$file" line with the target location for your attachment (i.e. C:\directory\file) - leave the $timestamp variable.
$timestamp = Get-Date -UFormat %Y%b%d
$file = "c:\horizon\horizon-usage-$timestamp.txt"

$hzhealth.ConnectionData | Out-File $file


##Last step - output to file and email usage report.
$date = Get-Date -UFormat %c
$subject = "$hznode Horizon Report for $date"
$body = "Horizon Manager $hznode - Concurrent User Connection Report for $date - please now reset the highest users count by logging into https://$hznode/admin/#/license and clicking Reset Highest Count button"

##Change the three variables below for your environment: smtpserver, recipient, and sender.
$smtpserver = "mail.rainpole.com"
$recipient = "administrator@rainpole.com"
$sender = "administrator@rainpole.com"

Send-MailMessage -from $sender -Attachments $file -Body $body -SmtpServer $smtpserver -Subject $subject -To $recipient

0 comments on commit 364727c

Please sign in to comment.
You can’t perform that action at this time.