Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Workstation Componet Validation

$
0
0

Hi all

I am writing a script to check a few things on a Virtual machine to ensure that it meets a certain baseline(Services running, Hotfixes ...etc).   I am running into a problem with getting the display adapter in the report.  I can pull the information and display it separately, however I would like it in the same report to make it a bit easier for our deployment team.  Below is the script,  I am sure that there are a few things that can be written a little better as well.   Any and all input is appreciated

 

#################


$recipients = "me@you.com"
$fromEmail = "Validcheck@you.com"
$SMTPserver = "Mailserver"
$currentTime = Get-Date -Format "yyyy-MM-dd | hh:mm:ss tt"
$logTime = Get-Date -Format "yyyy-MM-dd_hh-mm"
$LogFile = "C:\Support\scripts\US-VDICheck-Report-$logTime.csv"
$Bodymsg = $Bodymsg = gc -Path c:\support\scripts\vdimigrationmsg.txt | Out-string


add-pssnapin Citrix*
add-pssnapin Admin*
#$vm=$()
#$Status=$()
#$collection = $()

# Set variable for computername
$vm = "MyMachine"

 

foreach ($vm in $vms)
{
# ping the machine to see if it is up
 if (Test-Connection $vm -Count 1 -ea 0 -Quiet)   
   { $Pingstatus = "Up"     


# Get the video adapters on the system
$displayAdapters = get-wmiobject win32_videocontroller –comp $vm | Select Description, DriverVersion


# Check services
  $icasvc = get-service -Name "Porticaservice" -computername $vm
  $icaDesktopsvc = get-service -name "Brokeragent" -computername $vm
  $DskWindowMgrsvc = get-service -name "UxSms" -computername $vm
  $vmviewagent = get-service -name "WSNM" -computername $vm
  $rgsAgent = get-service -name "rgsender" -computername $vm
  $GoToMYPC = get-service -name GoToMyPC -computernam $vm

# Checks to see if the Citrix Hotfixes are installed
 # ICAWS760WX64010
  $Registry_Location010 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{516E229D-D5EE-AE8A-F3AF-9EB09D0A6B46}'   
  $Remote_Registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix10 = $Remote_Registry010.OpenSubKey($Registry_Location010)
  $ctxhfx010 = $hotfix10.GetValue('HotfixName')
 # ICAWS760WX64014
  $Registry_Location014 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{54200A3F-5C4F-EF2B-FA7C-0B06BD5E5815}'   
  $Remote_Registry014 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix014 = $Remote_Registry014.OpenSubKey($Registry_Location014)
  $ctxhfx014 = $hotfix014.GetValue('HotfixName')
 #ICAWS760WX64024
  $Registry_Location024 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{62B4CE3B-687D-0D8B-0B4F-18FF3F5CE90E}'   
  $Remote_Registry024 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix024 = $Remote_Registry024.OpenSubKey($Registry_Location024)
  $ctxhfx024 = $hotfix024.GetValue('HotfixName')
 #ICAWS760WX64011
  $Registry_Location011 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{835CAFEE-2BD5-5189-991F-A2F50E57B9AD}'   
  $Remote_Registry011 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix011 = $Remote_Registry011.OpenSubKey($Registry_Location011)
  $ctxhfx011 = $hotfix011.GetValue('HotfixName')
 #ICAWS760WX64022
  $Registry_Location022 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{8F87C292-5616-82C8-44DC-28651D014337}'   
  $Remote_Registry022 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix022 = $Remote_Registry022.OpenSubKey($Registry_Location022)
  $ctxhfx022 = $hotfix022.GetValue('HotfixName')
 #ICAWS760WX64002
  $Registry_Location002 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{AB36927A-FEFA-2176-BE81-E0AFCBE71AE7}'   
  $Remote_Registry002 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix002 = $Remote_Registry002.OpenSubKey($Registry_Location002)
  $ctxhfx002 = $hotfix002.GetValue('HotfixName')
 #ICAWS760WX64005
  $Registry_Location005 = 'Software\Wow6432node\Citrix\XenDesktop\Hotfixes\{BB9345DB-52F0-76AD-0364-EB598913C8BC}'   
  $Remote_Registry005 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM)   
  $hotfix005 = $Remote_Registry005.OpenSubKey($Registry_Location005)
  $ctxhfx005 = $hotfix005.GetValue('HotfixName')

# if Desktop Mger services is stopped, Set to automatic and enable it
  if ($DskWindowMgrsvc.status -eq "Running")
   { set-service -name "UxSms" -computername $vm -startupType Automatic -Status Running}
   $DskWindowMgrsvc = get-service -name "UxSms" -computername $vm 
   }
 else    { $Pingstatus = "Down"} 
 
# Gets the broker info
 $XDstatus = Get-BrokerDesktop -adminaddress pwvrfpcxd002 -MachineName ad\$vm |Select MachineName,DesktopGroupName,RegistrationState,InMaintenanceMode,AgentVersion
 
 #compiles status
 $Status= @{
  "MachineName" = $vm;
  "pingStatus" = $Pingstatus;
  "XD_DesktopGroup" = $XDStatus.DesktopGroupName;
  "XD_RegistrationState" = $XDStatus.RegistrationState;
  "XD_AgentVersion" = $XDStatus.AgentVersion
  "MaintenanceMode" = $XDStatus.InMaintenanceMode
  "Citrix ICA Service" = $icasvc.Status
  "Citrix Desktop Service"  = $icaDesktopsvc.status
  "Desktop Window Manager Session Manager" = $DskWindowMgrsvc.Status
  "ICAWS760WX64010" = $ctxhfx010
  "ICAWS760WX64014" = $ctxhfx014
  "ICAWS760WX64024" = $ctxhfx024
  "ICAWS760WX64011" = $ctxhfx011
  "ICAWS760WX64022" = $ctxhfx022
  "ICAWS760WX64002" = $ctxhfx002
  "ICAWS760WX64005" = $ctxhfx005
  "VMView Agent" = $vmviewagent.Status
  "RGS Agent" = $rgsAgent.status
  "GoToMyPC" = $GoToMYPC.status
   }
 New-Object -TypeName PSObject -Property $status -OutVariable MachineStatus | out-Null
 $collection += $machinestatus
}

#Spit out display Adapter info
$displayAdapters

# Dump the results in to csv
$collection | Select MachineName, pingStatus, XD_RegistrationState, XD_Agentversion, MaintenanceMode, "Citrix ICA Service", "Citrix Desktop Service", "Desktop Window Manager Session Manager","ICAWS760WX64002","ICAWS760WX64005","ICAWS760WX64010","ICAWS760WX64011","ICAWS760WX64014","ICAWS760WX64022","ICAWS760WX64024", "VMView Agent", "RGS Agent", "GoToMyPC", XD_DesktopGroup | Export-csv $LogFile  -NoTypeInformation
$logfile
$displayadapters | out-gridview

# mail CSV with message
send-mailmessage -from $fromEmail -to $recipients -subject "VDI Post Migration Check | $currentTime | $DDC " -Body $Bodymsg -Attachments $LogFile -SmtpServer $SMTPserver -Priority High

#####################################


Viewing all articles
Browse latest Browse all 6937

Trending Articles