Documente Academic
Documente Profesional
Documente Cultură
0
#This File is in Unicode format. Do not edit in an ASCII editor.
<#
.SYNOPSIS
Creates a complete inventory of a Citrix XenApp 6.5 farm using Microsoft Word
2010, 2013 or 2016.
.DESCRIPTION
Creates a complete inventory of a Citrix XenApp 6.5 farm using Microsoft Word
and PowerShell.
Creates either a Word document or PDF named after the XenApp 6.5 farm.
Document includes a Cover Page, Table of Contents and Footer.
Version 4.xx includes support for the following language versions of
Microsoft Word:
Catalan
Chinese
Danish
Dutch
English
Finnish
French
German
Norwegian
Portuguese
Spanish
Swedish
.PARAMETER CompanyName
Company Name to use for the Cover Page.
Default value is contained in
HKCU:\Software\Microsoft\Office\Common\UserInfo\CompanyName or
HKCU:\Software\Microsoft\Office\Common\UserInfo\Company, whichever is
populated on the
computer running the script.
This parameter has an alias of CN.
.PARAMETER CompanyAddress
Company Address to use for the Cover Page, if the Cover Page has the Address
field.
The following Cover Pages have an Address field:
Banded (Word 2013/2016)
Contrast (Word 2010)
Exposure (Word 2010)
Filigree (Word 2013/2016)
Ion (Dark) (Word 2013/2016)
Retrospect (Word 2013/2016)
Semaphore (Word 2013/2016)
Tiles (Word 2010)
ViewMaster (Word 2013/2016)
This parameter is only valid with the MSWORD and PDF output parameters.
This parameter has an alias of CA.
.PARAMETER CompanyEmail
Company Email to use for the Cover Page, if the Cover Page has the Email
field.
The following Cover Pages have an Email field:
Facet (Word 2013/2016)
This parameter is only valid with the MSWORD and PDF output parameters.
This parameter has an alias of CE.
.PARAMETER CompanyFax
Company Fax to use for the Cover Page, if the Cover Page has the Fax field.
The following Cover Pages have a Fax field:
Contrast (Word 2010)
Exposure (Word 2010)
This parameter is only valid with the MSWORD and PDF output parameters.
This parameter has an alias of CF.
.PARAMETER CompanyPhone
Company Phone to use for the Cover Page, if the Cover Page has the Phone
field.
The following Cover Pages have a Phone field:
Contrast (Word 2010)
Exposure (Word 2010)
This parameter is only valid with the MSWORD and PDF output parameters.
This parameter has an alias of CPh.
.PARAMETER CoverPage
What Microsoft Word Cover Page to use.
Only Word 2010, 2013 and 2016 are supported.
(default cover pages in Word en-US)
Will use all Default values and save the document as a PDF file.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Will use all Default values and add additional information for each server
about its hardware.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Will use all Default values and add additional information for each server
about its installed applications.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Will use all Default values and add additional information for each server
about its installed applications.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Carl Webster for the Company Name.
Sideline for the Cover Page format.
Administrator for the User Name.
Will return all Configuration Logging entries from "01/01/2017 00:00:00"
through "01/02/2017 "00:00:00".
.EXAMPLE
PS C:\PSScript > .\XA65_Inventory_V43.ps1 -StartDate "01/01/2017" -EndDate
"01/01/2017"
Will use all Default values and add additional information for each server
about its installed applications.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Will use all Default values and add additional information for each server
about its installed applications.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Will use:
Carl Webster Consulting for the Company Name.
Mod for the Cover Page format.
Carl Webster for the User Name.
.EXAMPLE
PS C:\PSScript .\XA65_Inventory_V43.ps1 -CN "Carl Webster Consulting" -CP
"Mod" -UN "Carl Webster"
Will use:
Carl Webster Consulting for the Company Name (alias CN).
Mod for the Cover Page format (alias CP).
Carl Webster for the User Name (alias UN).
.EXAMPLE
PS C:\PSScript .\XA65_Inventory_V43.ps1 -CompanyName "Sherlock Holmes
Consulting" `
-CoverPage Exposure -UserName "Dr. Watson" `
-CompanyAddress "221B Baker Street, London, England" `
-CompanyFax "+44 1753 276600" `
-CompanyPhone "+44 1753 276200"
Will use:
Sherlock Holmes Consulting for the Company Name.
Exposure for the Cover Page format.
Dr. Watson for the User Name.
221B Baker Street, London, England for the Company Address.
+44 1753 276600 for the Company Fax.
+44 1753 276200 for the Compnay Phone.
.EXAMPLE
PS C:\PSScript .\XA65_Inventory_V43.ps1 -CompanyName "Sherlock Holmes
Consulting" `
-CoverPage Facet -UserName "Dr. Watson" `
-CompanyEmail SuperSleuth@SherlockHolmes.com
Will use:
Sherlock Holmes Consulting for the Company Name.
Facet for the Cover Page format.
Dr. Watson for the User Name.
SuperSleuth@SherlockHolmes.com for the Compnay Email.
.EXAMPLE
PS C:\PSScript > .\XA65_Inventory_V43.ps1 -Section Policies
Will use all Default values and save the document as a PDF file.
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\CompanyName="Carl
Webster" or
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company="Carl
Webster"
$env:username = Administrator
Script will use the email server smtp.office365.com on port 587 using SSL,
sending from webster@carlwebster.com, sending to ITGroup@carlwebster.com.
If the current user's credentials are not valid to send email, the user will
be prompted to enter valid credentials.
.INPUTS
None. You cannot pipe objects to this script.
.OUTPUTS
No objects are output from this script. This script creates a Word or PDF
document.
.NOTES
NAME: XA65_Inventory_V43.ps1
VERSION: 4.33
AUTHOR: Carl Webster (with a lot of help from Michael B. Smith, Jeff Wouters
and Iain Brighton)
LASTEDIT: June 13, 2017
#>
#thanks to @jeffwouters and Michael B. Smith for helping me with these parameters
[CmdletBinding(SupportsShouldProcess = $False, ConfirmImpact = "None",
DefaultParameterSetName = "Word") ]
Param(
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Switch]$MSWord=$False,
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Switch]$PDF=$False,
[parameter(Mandatory=$False)]
[Switch]$Hardware=$False,
[parameter(Mandatory=$False)]
[Switch]$Software=$False,
[parameter(Mandatory=$False)]
[Datetime]$StartDate = ((Get-Date -displayhint date).AddDays(-7)),
[parameter(Mandatory=$False)]
[Datetime]$EndDate = (Get-Date -displayhint date),
[parameter(Mandatory=$False)]
[Switch]$Summary=$False,
[parameter(Mandatory=$False)]
[Switch]$AddDateTime=$False,
[parameter(Mandatory=$False)]
[string]$Section="All",
[parameter(Mandatory=$False)]
[string]$Folder="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CN")]
[ValidateNotNullOrEmpty()]
[string]$CompanyName="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CA")]
[ValidateNotNullOrEmpty()]
[string]$CompanyAddress="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CE")]
[ValidateNotNullOrEmpty()]
[string]$CompanyEmail="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CF")]
[ValidateNotNullOrEmpty()]
[string]$CompanyFax="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CPh")]
[ValidateNotNullOrEmpty()]
[string]$CompanyPhone="",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("CP")]
[ValidateNotNullOrEmpty()]
[string]$CoverPage="Sideline",
[parameter(ParameterSetName="Word",Mandatory=$False)]
[parameter(ParameterSetName="PDF",Mandatory=$False)]
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[Alias("UN")]
[ValidateNotNullOrEmpty()]
[string]$UserName=$env:username,
[parameter(ParameterSetName="SMTP",Mandatory=$True)]
[string]$SmtpServer="",
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[int]$SmtpPort=25,
[parameter(ParameterSetName="SMTP",Mandatory=$False)]
[switch]$UseSSL=$False,
[parameter(ParameterSetName="SMTP",Mandatory=$True)]
[string]$From="",
[parameter(ParameterSetName="SMTP",Mandatory=$True)]
[string]$To=""
Set-StrictMode -Version 2
#force on
$PSDefaultParameterValues = @{"*:Verbose"=$True}
$SaveEAPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
If($MSWord)
{
Write-Verbose "$(Get-Date): MSWord is set"
}
ElseIf($PDF)
{
Write-Verbose "$(Get-Date): PDF is set"
}
Else
{
$ErrorActionPreference = $SaveEAPreference
Write-Verbose "$(Get-Date): Unable to determine output parameter"
If($MSWord -eq $Null)
{
Write-Verbose "$(Get-Date): MSWord is Null"
}
ElseIf($PDF -eq $Null)
{
Write-Verbose "$(Get-Date): PDF is Null"
}
Else
{
Write-Verbose "$(Get-Date): MSWord is $($MSWord)"
Write-Verbose "$(Get-Date): PDF is $($PDF)"
}
Write-Error "Unable to determine output parameter. Script cannot continue"
Exit
}
If($Folder -ne "")
{
Write-Verbose "$(Get-Date): Testing folder path"
#does it exist
If(Test-Path $Folder -EA 0)
{
#it exists, now check to see if it is a folder and not a file
If(Test-Path $Folder -pathType Container -EA 0)
{
#it exists and it is a folder
Write-Verbose "$(Get-Date): Folder path $Folder exists and is a
folder"
}
Else
{
#it exists but it is a file not a folder
Write-Error "Folder $Folder is a file, not a folder. Script
cannot continue"
Exit
}
}
Else
{
#does not exist
Write-Error "Folder $Folder does not exist. Script cannot continue"
Exit
}
}
$ValidSection = $False
Switch ($Section)
{
"Admins" {$ValidSection = $True}
"Apps" {$ValidSection = $True}
"ConfigLog" {$ValidSection = $True}
"LBPolicies" {$ValidSection = $True}
"LoadEvals" {$ValidSection = $True}
"Policies" {$ValidSection = $True}
"Servers" {$ValidSection = $True}
"WGs" {$ValidSection = $True}
"Zones" {$ValidSection = $True}
"All" {$ValidSection = $True}
}
[int]$PointsPerTabStop = 36
[int]$Indent0TabStops = 0 * $PointsPerTabStop
[int]$Indent1TabStops = 1 * $PointsPerTabStop
[int]$Indent2TabStops = 2 * $PointsPerTabStop
[int]$Indent3TabStops = 3 * $PointsPerTabStop
[int]$Indent4TabStops = 4 * $PointsPerTabStop
# http://www.thedoctools.com/index.php?
show=wt_style_names_english_danish_german_french
[int]$wdStyleHeading1 = -2
[int]$wdStyleHeading2 = -3
[int]$wdStyleHeading3 = -4
[int]$wdStyleHeading4 = -5
[int]$wdStyleNoSpacing = -158
[int]$wdTableGrid = -155
#http://groovy.codehaus.org/modules/scriptom/1.6.0/scriptom-office-2K3-
tlb/apidocs/org/codehaus/groovy/scriptom/tlb/office/word/WdLineStyle.html
[int]$wdLineStyleNone = 0
[int]$wdLineStyleSingle = 1
[int]$wdHeadingFormatTrue = -1
[int]$wdHeadingFormatFalse = 0
}
$error.Clear()
If($UseSSL)
{
Write-Verbose "$(Get-Date): Trying to send email using current user's
credentials with SSL"
Send-MailMessage -Attachments $emailAttachment -Body $emailBody
-BodyAsHtml -From $From `
-Port $SmtpPort -SmtpServer $SmtpServer -Subject $emailSubject -To $To
`
-UseSSL *>$Null
}
Else
{
Write-Verbose "$(Get-Date): Trying to send email using current user's
credentials without SSL"
Send-MailMessage -Attachments $emailAttachment -Body $emailBody
-BodyAsHtml -From $From `
-Port $SmtpPort -SmtpServer $SmtpServer -Subject $emailSubject -To $To
*>$Null
}
$e = $error[0]
If($e.Exception.ToString().Contains("5.7.57"))
{
#The server response was: 5.7.57 SMTP; Client was not authenticated to
send anonymous mail during MAIL FROM
Write-Verbose "$(Get-Date): Current user's credentials failed. Ask for
usable credentials."
$error.Clear()
If($UseSSL)
{
Send-MailMessage -Attachments $emailAttachment -Body $emailBody
-BodyAsHtml -From $From `
-Port $SmtpPort -SmtpServer $SmtpServer -Subject $emailSubject
-To $To `
-UseSSL -credential $emailCredentials *>$Null
}
Else
{
Send-MailMessage -Attachments $emailAttachment -Body $emailBody
-BodyAsHtml -From $From `
-Port $SmtpPort -SmtpServer $SmtpServer -Subject $emailSubject
-To $To `
-credential $emailCredentials *>$Null
}
$e = $error[0]
[bool]$GotComputerItems = $True
Try
{
$Results = Get-WmiObject -computername $RemoteComputerName
win32_computersystem
}
Catch
{
$Results = $Null
}
ForEach($Item in $ComputerItems)
{
OutputComputerItem $Item
}
}
ElseIf(!$?)
{
Write-Verbose "$(Get-Date): Get-WmiObject win32_computersystem failed
for $($RemoteComputerName)"
Write-Warning "Get-WmiObject win32_computersystem failed for $
($RemoteComputerName)"
If($MSWORD -or $PDF)
{
WriteWordLine 0 2 "Get-WmiObject win32_computersystem failed for
$($RemoteComputerName)" "" $Null 0 $False $True
WriteWordLine 0 2 "On $($RemoteComputerName) you may need to run
winmgmt /verifyrepository" "" $Null 0 $False $True
WriteWordLine 0 2 "and winmgmt /salvagerepository. If this is a
trusted Forest, you may" "" $Null 0 $False $True
WriteWordLine 0 2 "need to rerun the script with Domain Admin
credentials from the trusted Forest." "" $Null 0 $False $True
}
}
Else
{
Write-Verbose "$(Get-Date): No results Returned for Computer
information"
If($MSWORD -or $PDF)
{
WriteWordLine 0 2 "No results Returned for Computer information"
"" $Null 0 $False $True
}
}
[bool]$GotDrives = $True
Try
{
$Results = Get-WmiObject -computername $RemoteComputerName
Win32_LogicalDisk
}
Catch
{
$Results = $Null
}
[bool]$GotProcessors = $True
Try
{
$Results = Get-WmiObject -computername $RemoteComputerName
win32_Processor
}
Catch
{
$Results = $Null
}
#Get Nics
Write-Verbose "$(Get-Date): `t`t`tNIC information"
[bool]$GotNics = $True
Try
{
$Results = Get-WmiObject -computername $RemoteComputerName
win32_networkadapterconfiguration
}
Catch
{
$Results
}
If($GotNics)
{
ForEach($nic in $nics)
{
Try
{
$ThisNic = Get-WmiObject -computername
$RemoteComputerName win32_networkadapter | Where {$_.index -eq $nic.index}
}
Catch
{
$ThisNic = $Null
}
$Results = $Null
$ComputerItems = $Null
$Drives = $Null
$Processors = $Null
$Nics = $Null
}
Function OutputComputerItem
{
Param([object]$Item)
If($MSWord -or $PDF)
{
[System.Collections.Hashtable[]] $ItemInformation = @()
$ItemInformation += @{ Data = "Manufacturer"; Value =
$Item.manufacturer; }
$ItemInformation += @{ Data = "Model"; Value = $Item.model; }
$ItemInformation += @{ Data = "Domain"; Value = $Item.domain; }
$ItemInformation += @{ Data = "Total Ram"; Value = "$
($Item.totalphysicalram) GB"; }
$ItemInformation += @{ Data = "Physical Processors (sockets)"; Value =
$Item.NumberOfProcessors; }
$ItemInformation += @{ Data = "Logical Processors (cores w/HT)"; Value
= $Item.NumberOfLogicalProcessors; }
$Table = AddWordTable -Hashtable $ItemInformation `
-Columns Data,Value `
-List `
-AutoFit $wdAutoFitFixed;
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustNone)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 2 ""
}
}
Function OutputDriveItem
{
Param([object]$Drive)
$xDriveType = ""
Switch ($drive.drivetype)
{
0 {$xDriveType = "Unknown"}
1 {$xDriveType = "No Root Directory"}
2 {$xDriveType = "Removable Disk"}
3 {$xDriveType = "Local Disk"}
4 {$xDriveType = "Network Drive"}
5 {$xDriveType = "Compact Disc"}
6 {$xDriveType = "RAM Disk"}
Default {$xDriveType = "Unknown"}
}
$xVolumeDirty = ""
If(![String]::IsNullOrEmpty($drive.volumedirty))
{
If($drive.volumedirty)
{
$xVolumeDirty = "Yes"
}
Else
{
$xVolumeDirty = "No"
}
}
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 2 ""
}
}
Function OutputProcessorItem
{
Param([object]$Processor)
$xAvailability = ""
Switch ($processor.availability)
{
1 {$xAvailability = "Other"}
2 {$xAvailability = "Unknown"}
3 {$xAvailability = "Running or Full Power"}
4 {$xAvailability = "Warning"}
5 {$xAvailability = "In Test"}
6 {$xAvailability = "Not Applicable"}
7 {$xAvailability = "Power Off"}
8 {$xAvailability = "Off Line"}
9 {$xAvailability = "Off Duty"}
10 {$xAvailability = "Degraded"}
11 {$xAvailability = "Not Installed"}
12 {$xAvailability = "Install Error"}
13 {$xAvailability = "Power Save - Unknown"}
14 {$xAvailability = "Power Save - Low Power Mode"}
15 {$xAvailability = "Power Save - Standby"}
16 {$xAvailability = "Power Cycle"}
17 {$xAvailability = "Power Save - Warning"}
Default {$xAvailability = "Unknown"}
}
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 0 ""
}
}
Function OutputNicItem
{
Param([object]$Nic, [object]$ThisNic)
$xAvailability = ""
Switch ($processor.availability)
{
1 {$xAvailability = "Other"}
2 {$xAvailability = "Unknown"}
3 {$xAvailability = "Running or Full Power"}
4 {$xAvailability = "Warning"}
5 {$xAvailability = "In Test"}
6 {$xAvailability = "Not Applicable"}
7 {$xAvailability = "Power Off"}
8 {$xAvailability = "Off Line"}
9 {$xAvailability = "Off Duty"}
10 {$xAvailability = "Degraded"}
11 {$xAvailability = "Not Installed"}
12 {$xAvailability = "Install Error"}
13 {$xAvailability = "Power Save - Unknown"}
14 {$xAvailability = "Power Save - Low Power Mode"}
15 {$xAvailability = "Power Save - Standby"}
16 {$xAvailability = "Power Cycle"}
17 {$xAvailability = "Power Save - Warning"}
Default {$xAvailability = "Unknown"}
}
$xIPAddress = @()
ForEach($IPAddress in $Nic.ipaddress)
{
$xIPAddress += "$($IPAddress)"
}
$xIPSubnet = @()
ForEach($IPSubnet in $Nic.ipsubnet)
{
$xIPSubnet += "$($IPSubnet)"
}
$xdnsenabledforwinsresolution = ""
If($nic.dnsenabledforwinsresolution)
{
$xdnsenabledforwinsresolution = "Yes"
}
Else
{
$xdnsenabledforwinsresolution = "No"
}
$xTcpipNetbiosOptions = ""
Switch ($nic.TcpipNetbiosOptions)
{
0 {$xTcpipNetbiosOptions = "Use NetBIOS setting from DHCP Server"}
1 {$xTcpipNetbiosOptions = "Enable NetBIOS"}
2 {$xTcpipNetbiosOptions = "Disable NetBIOS"}
Default {$xTcpipNetbiosOptions = "Unknown"}
}
$xwinsenablelmhostslookup = ""
If($nic.winsenablelmhostslookup)
{
$xwinsenablelmhostslookup = "Yes"
}
Else
{
$xwinsenablelmhostslookup = "No"
}
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
}
}
#endregion
Function SetWordHashTable
{
Param([string]$CultureCode)
#ca - Catalan
#da - Danish
#de - German
#en - English
#es - Spanish
#fi - Finnish
#fr - French
#nb - Norwegian
#nl - Dutch
#pt - Portuguese
#sv - Swedish
#zh - Chinese
[string]$toc = $(
Switch ($CultureCode)
{
'ca-' { 'Taula automática 2'; Break }
'da-' { 'Automatisk tabel 2'; Break }
'de-' { 'Automatische Tabelle 2'; Break }
'en-' { 'Automatic Table 2'; Break }
'es-' { 'Tabla automática 2'; Break }
'fi-' { 'Automaattinen taulukko 2'; Break }
'fr-' { 'Table automatique 2'; Break } #changed 13-feb-2017 david
roquier and samuel legrand
'nb-' { 'Automatisk tabell 2'; Break }
'nl-' { 'Automatische inhoudsopgave 2'; Break }
'pt-' { 'Sumário Automático 2'; Break }
'sv-' { 'Automatisk innehållsförteckning2'; Break }
'zh-' { '自动目录 2'; Break }
}
)
$Script:myHash = @{}
$Script:myHash.Word_TableOfContents = $toc
$Script:myHash.Word_NoSpacing = $wdStyleNoSpacing
$Script:myHash.Word_Heading1 = $wdStyleheading1
$Script:myHash.Word_Heading2 = $wdStyleheading2
$Script:myHash.Word_Heading3 = $wdStyleheading3
$Script:myHash.Word_Heading4 = $wdStyleheading4
$Script:myHash.Word_TableGrid = $wdTableGrid
}
Function GetCulture
{
Param([int]$WordValue)
#codes obtained from http://support.microsoft.com/kb/221435
#http://msdn.microsoft.com/en-us/library/bb213877(v=office.12).aspx
$CatalanArray = 1027
$ChineseArray = 2052,3076,5124,4100
$DanishArray = 1030
$DutchArray = 2067, 1043
$EnglishArray = 3081, 10249, 4105, 9225, 6153, 8201, 5129, 13321, 7177,
11273, 2057, 1033, 12297
$FinnishArray = 1035
$FrenchArray = 2060, 1036, 11276, 3084, 12300, 5132, 13324, 6156, 8204,
10252, 7180, 9228, 4108
$GermanArray = 1031, 3079, 5127, 4103, 2055
$NorwegianArray = 1044, 2068
$PortugueseArray = 1046, 2070
$SpanishArray = 1034, 11274, 16394, 13322, 9226, 5130, 7178, 12298, 17418,
4106, 18442, 19466, 6154, 15370, 10250, 20490, 3082, 14346, 8202
$SwedishArray = 1053, 2077
#ca - Catalan
#da - Danish
#de - German
#en - English
#es - Spanish
#fi - Finnish
#fr - French
#nb - Norwegian
#nl - Dutch
#pt - Portuguese
#sv - Swedish
#zh - Chinese
Switch ($WordValue)
{
{$CatalanArray -contains $_} {$CultureCode = "ca-"}
{$ChineseArray -contains $_} {$CultureCode = "zh-"}
{$DanishArray -contains $_} {$CultureCode = "da-"}
{$DutchArray -contains $_} {$CultureCode = "nl-"}
{$EnglishArray -contains $_} {$CultureCode = "en-"}
{$FinnishArray -contains $_} {$CultureCode = "fi-"}
{$FrenchArray -contains $_} {$CultureCode = "fr-"}
{$GermanArray -contains $_} {$CultureCode = "de-"}
{$NorwegianArray -contains $_} {$CultureCode = "nb-"}
{$PortugueseArray -contains $_} {$CultureCode = "pt-"}
{$SpanishArray -contains $_} {$CultureCode = "es-"}
{$SwedishArray -contains $_} {$CultureCode = "sv-"}
Default {$CultureCode = "en-"}
}
Return $CultureCode
}
Function ValidateCoverPage
{
Param([int]$xWordVersion, [string]$xCP, [string]$CultureCode)
$xArray = ""
Switch ($CultureCode)
{
'ca-' {
If($xWordVersion -eq $wdWord2016)
{
$xArray = ("Austin", "En bandes", "Faceta",
"Filigrana",
"Integral", "Ió (clar)", "Ió (fosc)", "Línia
lateral",
"Moviment", "Quadrícula", "Retrospectiu", "Sector
(clar)",
"Sector (fosc)", "Semàfor", "Visualització
principal", "Whisp")
}
ElseIf($xWordVersion -eq $wdWord2013)
{
$xArray = ("Austin", "En bandes", "Faceta",
"Filigrana",
"Integral", "Ió (clar)", "Ió (fosc)", "Línia
lateral",
"Moviment", "Quadrícula", "Retrospectiu", "Sector
(clar)",
"Sector (fosc)", "Semàfor", "Visualització", "Whisp")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alfabet", "Anual", "Austin",
"Conservador",
"Contrast", "Cubicles", "Diplomàtic", "Exposició",
"Línia lateral", "Mod", "Mosiac", "Moviment", "Paper
de diari",
"Perspectiva", "Piles", "Quadrícula", "Sobri",
"Transcendir", "Trencaclosques")
}
}
'da-' {
If($xWordVersion -eq $wdWord2016)
{
$xArray = ("Austin", "BevægElse", "Brusen", "Facet",
"Filigran",
"Gitter", "Integral", "Ion (lys)", "Ion (mørk)",
"Retro", "Semafor", "Sidelinje", "Stribet",
"Udsnit (lys)", "Udsnit (mørk)", "Visningsmaster")
}
ElseIf($xWordVersion -eq $wdWord2013)
{
$xArray = ("BevægElse", "Brusen", "Ion (lys)",
"Filigran",
"Retro", "Semafor", "Visningsmaster", "Integral",
"Facet", "Gitter", "Stribet", "Sidelinje", "Udsnit
(lys)",
"Udsnit (mørk)", "Ion (mørk)", "Austin")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("BevægElse", "Moderat", "Perspektiv",
"Firkanter",
"Overskrid", "Alfabet", "Kontrast", "Stakke",
"Fliser", "Gåde",
"Gitter", "Austin", "Eksponering", "Sidelinje",
"Enkel",
"Nålestribet", "Årlig", "Avispapir", "Tradionel")
}
}
'de-' {
If($xWordVersion -eq $wdWord2016)
{
$xArray = ("Austin", "Bewegung", "Facette",
"Filigran",
"Gebändert", "Integral", "Ion (dunkel)", "Ion
(hell)",
"Pfiff", "Randlinie", "Raster", "Rückblick",
"Segment (dunkel)", "Segment (hell)", "Semaphor",
"ViewMaster")
}
ElseIf($xWordVersion -eq $wdWord2013)
{
$xArray = ("Semaphor", "Segment (hell)", "Ion
(hell)",
"Raster", "Ion (dunkel)", "Filigran", "Rückblick",
"Pfiff",
"ViewMaster", "Segment (dunkel)", "Verbunden",
"Bewegung",
"Randlinie", "Austin", "Integral", "Facette")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alphabet", "Austin", "Bewegung",
"Durchscheinend",
"Herausgestellt", "Jährlich", "Kacheln", "Kontrast",
"Kubistisch",
"Modern", "Nadelstreifen", "Perspektive", "Puzzle",
"Randlinie",
"Raster", "Schlicht", "Stapel", "Traditionell",
"Zeitungspapier")
}
}
'en-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("Austin", "Banded", "Facet", "Filigree",
"Grid",
"Integral", "Ion (Dark)", "Ion (Light)", "Motion",
"Retrospect",
"Semaphore", "Sideline", "Slice (Dark)", "Slice
(Light)", "ViewMaster",
"Whisp")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alphabet", "Annual", "Austere", "Austin",
"Conservative",
"Contrast", "Cubicles", "Exposure", "Grid", "Mod",
"Motion", "Newsprint",
"Perspective", "Pinstripes", "Puzzle", "Sideline",
"Stacks", "Tiles", "Transcend")
}
}
'es-' {
If($xWordVersion -eq $wdWord2016)
{
$xArray = ("Austin", "Con bandas", "Cortar (oscuro)",
"Cuadrícula",
"Whisp", "Faceta", "Filigrana", "Integral", "Ion
(claro)",
"Ion (oscuro)", "Línea lateral", "Movimiento",
"Retrospectiva",
"Semáforo", "Slice (luz)", "Vista principal",
"Whisp")
}
ElseIf($xWordVersion -eq $wdWord2013)
{
$xArray = ("Whisp", "Vista principal", "Filigrana",
"Austin",
"Slice (luz)", "Faceta", "Semáforo", "Retrospectiva",
"Cuadrícula",
"Movimiento", "Cortar (oscuro)", "Línea lateral",
"Ion (oscuro)",
"Ion (claro)", "Integral", "Con bandas")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alfabeto", "Anual", "Austero", "Austin",
"Conservador",
"Contraste", "Cuadrícula", "Cubículos", "Exposición",
"Línea lateral",
"Moderno", "Mosaicos", "Movimiento", "Papel
periódico",
"Perspectiva", "Pilas", "Puzzle", "Rayas",
"Sobrepasar")
}
}
'fi-' {
If($xWordVersion -eq $wdWord2016)
{
$xArray = ("Filigraani", "Integraali", "Ioni
(tumma)",
"Ioni (vaalea)", "Opastin", "Pinta", "Retro",
"Sektori (tumma)",
"Sektori (vaalea)", "Vaihtuvavärinen", "ViewMaster",
"Austin",
"Kuiskaus", "Liike", "Ruudukko", "Sivussa")
}
ElseIf($xWordVersion -eq $wdWord2013)
{
$xArray = ("Filigraani", "Integraali", "Ioni
(tumma)",
"Ioni (vaalea)", "Opastin", "Pinta", "Retro",
"Sektori (tumma)",
"Sektori (vaalea)", "Vaihtuvavärinen", "ViewMaster",
"Austin",
"Kiehkura", "Liike", "Ruudukko", "Sivussa")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Aakkoset", "Askeettinen", "Austin",
"Kontrasti",
"Laatikot", "Liike", "Liituraita", "Mod", "Osittain
peitossa",
"Palapeli", "Perinteinen", "Perspektiivi", "Pinot",
"Ruudukko",
"Ruudut", "Sanomalehtipaperi", "Sivussa",
"Vuotuinen", "Ylitys")
}
}
'fr-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("À bandes", "Austin", "Facette",
"Filigrane",
"Guide", "Intégrale", "Ion (clair)", "Ion (foncé)",
"Lignes latérales", "Quadrillage", "Rétrospective",
"Secteur (clair)",
"Secteur (foncé)", "Sémaphore", "ViewMaster",
"Whisp")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alphabet", "Annuel", "Austère", "Austin",
'nb-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("Austin", "BevegElse", "Dempet", "Fasett",
"Filigran",
"Integral", "Ion (lys)", "Ion (mørk)", "Retrospekt",
"Rutenett",
"Sektor (lys)", "Sektor (mørk)", "Semafor",
"Sidelinje", "Stripet",
"ViewMaster")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alfabet", "Årlig", "Avistrykk", "Austin",
"Avlukker",
"BevegElse", "Engasjement", "Enkel", "Fliser",
"Konservativ",
"Kontrast", "Mod", "Perspektiv", "Puslespill",
"Rutenett", "Sidelinje",
"Smale striper", "Stabler", "Transcenderende")
}
}
'nl-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("Austin", "Beweging", "Facet",
"Filigraan", "Gestreept",
"Integraal", "Ion (donker)", "Ion (licht)", "Raster",
"Segment (Light)", "Semafoor", "Slice (donker)",
"Spriet",
"Terugblik", "Terzijde", "ViewMaster")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Aantrekkelijk", "Alfabet", "Austin",
"Bescheiden",
"Beweging", "Blikvanger", "Contrast", "Eenvoudig",
"Jaarlijks",
"Krantenpapier", "Krijtstreep", "Kubussen", "Mod",
"Perspectief",
"Puzzel", "Raster", "Stapels",
"Tegels", "Terzijde")
}
}
'pt-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("Animação", "Austin", "Em Tiras",
"Exibição Mestra",
"Faceta", "Fatia (Clara)", "Fatia (Escura)",
"Filete", "Filigrana",
"Grade", "Integral", "Íon (Claro)", "Íon (Escuro)",
"Linha Lateral",
"Retrospectiva", "Semáforo")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alfabeto", "Animação", "Anual",
"Austero", "Austin", "Baias",
"Conservador", "Contraste", "Exposição", "Grade",
"Ladrilhos",
"Linha Lateral", "Listras", "Mod", "Papel Jornal",
"Perspectiva", "Pilhas",
"Quebra-cabeça", "Transcend")
}
}
'sv-' {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion -eq
$wdWord2016)
{
$xArray = ("Austin", "Band", "Fasett", "Filigran",
"Integrerad", "Jon (ljust)",
"Jon (mörkt)", "Knippe", "Rutnät", "RörElse", "Sektor
(ljus)", "Sektor (mörk)",
"Semafor", "Sidlinje", "VisaHuvudsida", "Återblick")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alfabetmönster", "Austin", "Enkelt",
"Exponering", "Konservativt",
"Kontrast", "Kritstreck", "Kuber", "Perspektiv",
"Plattor", "Pussel", "Rutnät",
"RörElse", "Sidlinje", "Sobert", "Staplat",
"Tidningspapper", "Årligt",
"Övergående")
}
}
'zh-' {
If($xWordVersion -eq $wdWord2010 -or $xWordVersion -eq
$wdWord2013 -or $xWordVersion -eq $wdWord2016)
{
$xArray = ('奥斯汀', '边线型', '花丝', '怀旧', '积分',
'离子(浅色)', '离子(深色)', '母版型', '平面', '切片(浅色)',
'切片(深色)', '丝状', '网格', '镶边', '信号灯',
'运动型')
}
}
Default {
If($xWordVersion -eq $wdWord2013 -or $xWordVersion
-eq $wdWord2016)
{
$xArray = ("Austin", "Banded", "Facet",
"Filigree", "Grid",
"Integral", "Ion (Dark)", "Ion (Light)",
"Motion", "Retrospect",
"Semaphore", "Sideline", "Slice (Dark)", "Slice
(Light)", "ViewMaster",
"Whisp")
}
ElseIf($xWordVersion -eq $wdWord2010)
{
$xArray = ("Alphabet", "Annual", "Austere",
"Austin", "Conservative",
"Contrast", "Cubicles", "Exposure", "Grid",
"Mod", "Motion", "Newsprint",
"Perspective", "Pinstripes", "Puzzle",
"Sideline", "Stacks", "Tiles", "Transcend")
}
}
}
Function ConvertTo-ScriptBlock
{
#by Jeff Wouters, PowerShell MVP
Param([string]$string)
$ScriptBlock = $executioncontext.invokecommand.NewScriptBlock($string)
Return $ScriptBlock
}
Function SWExclusions
{
# original work by Shaun Ritchie
# performance improvements by Jeff Wouters, PowerShell MVP
# modified by Webster
# modified 3-jan-2014 to add displayversion
# bug found 30-jul-2014 by Sam Jacobs
# this function did not work if the SoftwareExlusions.txt file contained only
one line
$var = ""
$Tmp = '$InstalledApps | Where {'
$Exclusions = Get-Content "$($pwd.path)\SoftwareExclusions.txt" -EA 0
If($? -and $Exclusions -ne $Null)
{
If($Exclusions -is [array])
{
ForEach($Exclusion in $Exclusions)
{
$Tmp += "(`$`_.DisplayName -notlike ""$($Exclusion)"") -and
"
}
$var += $Tmp.Substring(0,($Tmp.Length - 6))
}
Else
{
# added 30-jul-2014 to handle if the file contained only one line
$tmp += "(`$`_.DisplayName -notlike ""$($Exclusions)"")"
$var = $tmp
}
$var += "} | Select-Object DisplayName, DisplayVersion | Sort
DisplayName -unique"
}
return $var
}
Function CheckWordPrereq
{
If((Test-Path REGISTRY::HKEY_CLASSES_ROOT\Word.Application) -eq $False)
{
$ErrorActionPreference = $SaveEAPreference
Write-Host "`n`n`t`tThis script directly outputs to Microsoft Word,
please install Microsoft Word`n`n"
Exit
}
Function ValidateCompanyName
{
[bool]$xResult = Test-RegistryValue
"HKCU:\Software\Microsoft\Office\Common\UserInfo" "CompanyName"
If($xResult)
{
Return Get-RegistryValue
"HKCU:\Software\Microsoft\Office\Common\UserInfo" "CompanyName"
}
Else
{
$xResult = Test-RegistryValue
"HKCU:\Software\Microsoft\Office\Common\UserInfo" "Company"
If($xResult)
{
Return Get-RegistryValue
"HKCU:\Software\Microsoft\Office\Common\UserInfo" "Company"
}
Else
{
Return ""
}
}
}
#http://stackoverflow.com/questions/5648931/test-if-registry-value-exists
# This Function just gets $True or $False
Function Test-RegistryValue($path, $name)
{
$key = Get-Item -LiteralPath $path -EA 0
$key -and $Null -ne $key.GetValue($name, $Null)
}
Switch ($PriorityValue)
{
0 {"Very High"}
1 {"High"}
2 {"Medium"}
3 {"Low"}
Default {"Unknown Priority Value"}
}
Return $PriorityValue
}
Function ConvertNumberToTime
{
Param([int]$val = 0)
#this is stored as a number between 0 (00:00 AM) and 1439 (23:59 PM)
#180 = 3AM
#900 = 3PM
#1027 = 5:07 PM
#[int] (1027/60) = 17 or 5PM
#1027 % 60 leaves 7 or 7 minutes
Function ConvertIntegerToDate
{
#thanks to MBS for helping me on this Function
Param([int]$DateAsInteger = 0)
#this is stored as an integer but is actually a bitmask
#01/01/2013 = 131924225 = 11111011101 00000001 00000001
#01/17/2013 = 131924241 = 11111011101 00000001 00010001
#
# last 8 bits are the day
# previous 8 bits are the month
# the rest (up to 16) are the year
Return "$Month/$Day/$Year"
}
Function Check-LoadedModule
#Function created by Jeff Wouters
#@JeffWouters on Twitter
#modified by Michael B. Smith to handle when the module doesn't exist on server
#modified by @andyjmorgan
#bug fixed by @schose
#bug fixed by Peter Bosen
#This Function handles all three scenarios:
#
# 1. Module is already imported into current session
# 2. Module is not already imported into current session, it does exists on the
server and is imported
# 3. Module does not exist on the server
{
Param([parameter(Mandatory = $True)][alias("Module")][string]$ModuleName)
#$LoadedModules = Get-Module | Select Name
#following line changed at the recommendation of @andyjmorgan
$LoadedModules = Get-Module |% { $_.Name.ToString() }
#bug reported on 21-JAN-2013 by @schose
#the following line did not work if the citrix.grouppolicy.commands.psm1
module
#was manually loaded from a non Default folder
#$ModuleFound = (!$LoadedModules -like "*$ModuleName*")
Function Check-NeededPSSnapins
{
Param([parameter(Mandatory = $True)][alias("Snapin")][string[]]$Snapins)
#Function specifics
$MissingSnapins = @()
[bool]$FoundMissingSnapin = $False
$LoadedSnapins = @()
$RegisteredSnapins = @()
ForEach($Snapin in $Snapins)
{
#check if the snapin is loaded
If(!($LoadedSnapins -like $snapin))
{
#Check if the snapin is missing
If(!($RegisteredSnapins -like $Snapin))
{
#set the flag if it's not already
If(!($FoundMissingSnapin))
{
$FoundMissingSnapin = $True
}
#add the entry to the list
$MissingSnapins += $Snapin
}
Else
{
#Snapin is registered, but not loaded, loading it now:
Write-Host "Loading Windows PowerShell snap-in: $snapin"
Add-PSSnapin -Name $snapin -EA 0 *>$Null
}
}
}
If($FoundMissingSnapin)
{
Write-Warning "Missing Windows PowerShell snap-ins Detected:"
$missingSnapins | % {Write-Warning "($_)"}
Return $False
}
Else
{
Return $True
}
}
Function WriteWordLine
#Function created by Ryan Revord
#@rsrevord on Twitter
#Function created to make output to Word easy in this script
#updated 27-Mar-2014 to include font name, font size, italics and bold options
{
Param([int]$style=0,
[int]$tabs = 0,
[string]$name = '',
[string]$value = '',
[string]$fontName=$Null,
[int]$fontSize=0,
[bool]$italics=$False,
[bool]$boldface=$False,
[Switch]$nonewline)
#build # of tabs
While($tabs -gt 0)
{
$output += "`t"; $tabs--;
}
If(![String]::IsNullOrEmpty($fontName))
{
$Selection.Font.name = $fontName
}
If($fontSize -ne 0)
{
$Selection.Font.size = $fontSize
}
Function Set-DocumentProperty {
<#
.SYNOPSIS
Function to set the Title Page document properties in MS Word
.DESCRIPTION
Long description
.PARAMETER Document
Current Document Object
.PARAMETER DocProperty
Parameter description
.PARAMETER Value
Parameter description
.EXAMPLE
Set-DocumentProperty -Document $Script:Doc -DocProperty Title -Value
'MyTitle'
.EXAMPLE
Set-DocumentProperty -Document $Script:Doc -DocProperty Company -Value
'MyCompany'
.EXAMPLE
Set-DocumentProperty -Document $Script:Doc -DocProperty Author -Value 'Jim
Moyle'
.EXAMPLE
Set-DocumentProperty -Document $Script:Doc -DocProperty Subject -Value
'MySubjectTitle'
.NOTES
Function Created by Jim Moyle June 2017
Twitter : @JimMoyle
#>
param (
[object]$Document,
[String]$DocProperty,
[string]$Value
)
try {
$binding = "System.Reflection.BindingFlags" -as [type]
$builtInProperties = $Document.BuiltInDocumentProperties
$property = [System.__ComObject].invokemember("item",
$binding::GetProperty, $null, $BuiltinProperties, $DocProperty)
[System.__ComObject].invokemember("value", $binding::SetProperty, $null,
$property, $Value)
}
catch {
Write-Warning "Failed to set $DocProperty to $Value"
}
}
Function FindWordDocumentEnd
{
#return focus to main document
$Script:Doc.ActiveWindow.ActivePane.view.SeekView = $wdSeekMainDocument
#move to the end of the current document
$Script:Selection.EndKey($wdStory,$wdMove) | Out-Null
}
Function Get-PrinterModifiedSettings
{
Param([string]$Value, [string]$xelement, [bool]$xtable)
[string]$ReturnStr = ""
Switch ($Value)
{
"copi"
{
If($xtable)
{
$txt="Copies:"
}
Else
{
$txt="Copies`t`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
$ReturnStr = "$txt $tmp2"
}
}
"coll"
{
If($xtable)
{
$txt="Collate:"
}
Else
{
$txt="Collate`t`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
$ReturnStr = "$txt $tmp2"
}
}
"scal"
{
If($xtable)
{
$txt="Scale (%):"
}
Else
{
$txt="Scale (%)`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
$ReturnStr = "$txt $tmp2"
}
}
"colo"
{
If($xtable)
{
$txt="Color:"
}
Else
{
$txt="Color`t`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
1 {$tmp2 = "Monochrome"}
2 {$tmp2 = "Color"}
Default {$tmp2 = "Color could not be determined: $
($xelement)"}
}
$ReturnStr = "$txt $tmp2"
}
}
"prin"
{
If($xtable)
{
$txt="Print Quality:"
}
Else
{
$txt="Print Quality`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
-1 {$tmp2 = "150 dpi"}
-2 {$tmp2 = "300 dpi"}
-3 {$tmp2 = "600 dpi"}
-4 {$tmp2 = "1200 dpi"}
Default
{
$tmp2 = "Custom...`tX resolution: $tmp1"
}
}
$ReturnStr = "$txt $tmp2"
}
}
"yres"
{
If($xtable)
{
$txt="Y resolution:"
}
Else
{
$txt="Y resolution`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
$ReturnStr = "$txt $tmp2"
}
}
"orie"
{
If($xtable)
{
$txt="Orientation:"
}
Else
{
$txt="Orientation`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
"portrait" {$tmp2 = "Portrait"}
"landscape" {$tmp2 = "Landscape"}
Default {$tmp2 = "Orientation could not be
determined: $($xelement)"}
}
$ReturnStr = "$txt $tmp2"
}
}
"dupl"
{
If($xtable)
{
$txt="Duplex:"
}
Else
{
$txt="Duplex`t`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
1 {$tmp2 = "Simplex"}
2 {$tmp2 = "Vertical"}
3 {$tmp2 = "Horizontal"}
Default {$tmp2 = "Duplex could not be determined: $
($xelement)"}
}
$ReturnStr = "$txt $tmp2"
}
}
"pape"
{
If($xtable)
{
$txt="Paper Size:"
}
Else
{
$txt="Paper Size`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
1 {$tmp2 = "Letter"}
2 {$tmp2 = "Letter Small"}
3 {$tmp2 = "Tabloid"}
4 {$tmp2 = "Ledger"}
5 {$tmp2 = "Legal"}
6 {$tmp2 = "Statement"}
7 {$tmp2 = "Executive"}
8 {$tmp2 = "A3"}
9 {$tmp2 = "A4"}
10 {$tmp2 = "A4 Small"}
11 {$tmp2 = "A5"}
12 {$tmp2 = "B4 (JIS)"}
13 {$tmp2 = "B5 (JIS)"}
14 {$tmp2 = "Folio"}
15 {$tmp2 = "Quarto"}
16 {$tmp2 = "10X14"}
17 {$tmp2 = "11X17"}
18 {$tmp2 = "Note"}
19 {$tmp2 = "Envelope #9"}
20 {$tmp2 = "Envelope #10"}
21 {$tmp2 = "Envelope #11"}
22 {$tmp2 = "Envelope #12"}
23 {$tmp2 = "Envelope #14"}
24 {$tmp2 = "C Size Sheet"}
25 {$tmp2 = "D Size Sheet"}
26 {$tmp2 = "E Size Sheet"}
27 {$tmp2 = "Envelope DL"}
28 {$tmp2 = "Envelope C5"}
29 {$tmp2 = "Envelope C3"}
30 {$tmp2 = "Envelope C4"}
31 {$tmp2 = "Envelope C6"}
32 {$tmp2 = "Envelope C65"}
33 {$tmp2 = "Envelope B4"}
34 {$tmp2 = "Envelope B5"}
35 {$tmp2 = "Envelope B6"}
36 {$tmp2 = "Envelope Italy"}
37 {$tmp2 = "Envelope Monarch"}
38 {$tmp2 = "Envelope Personal"}
39 {$tmp2 = "US Std Fanfold"}
40 {$tmp2 = "German Std Fanfold"}
41 {$tmp2 = "German Legal Fanfold"}
42 {$tmp2 = "B4 (ISO)"}
43 {$tmp2 = "Japanese Postcard"}
44 {$tmp2 = "9X11"}
45 {$tmp2 = "10X11"}
46 {$tmp2 = "15X11"}
47 {$tmp2 = "Envelope Invite"}
48 {$tmp2 = "Reserved - DO NOT USE"}
49 {$tmp2 = "Reserved - DO NOT USE"}
50 {$tmp2 = "Letter Extra"}
51 {$tmp2 = "Legal Extra"}
52 {$tmp2 = "Tabloid Extra"}
53 {$tmp2 = "A4 Extra"}
54 {$tmp2 = "Letter Transverse"}
55 {$tmp2 = "A4 Transverse"}
56 {$tmp2 = "Letter Extra Transverse"}
57 {$tmp2 = "A Plus"}
58 {$tmp2 = "B Plus"}
59 {$tmp2 = "Letter Plus"}
60 {$tmp2 = "A4 Plus"}
61 {$tmp2 = "A5 Transverse"}
62 {$tmp2 = "B5 (JIS) Transverse"}
63 {$tmp2 = "A3 Extra"}
64 {$tmp2 = "A5 Extra"}
65 {$tmp2 = "B5 (ISO) Extra"}
66 {$tmp2 = "A2"}
67 {$tmp2 = "A3 Transverse"}
68 {$tmp2 = "A3 Extra Transverse"}
69 {$tmp2 = "Japanese Double Postcard"}
70 {$tmp2 = "A6"}
71 {$tmp2 = "Japanese Envelope Kaku #2"}
72 {$tmp2 = "Japanese Envelope Kaku #3"}
73 {$tmp2 = "Japanese Envelope Chou #3"}
74 {$tmp2 = "Japanese Envelope Chou #4"}
75 {$tmp2 = "Letter Rotated"}
76 {$tmp2 = "A3 Rotated"}
77 {$tmp2 = "A4 Rotated"}
78 {$tmp2 = "A5 Rotated"}
79 {$tmp2 = "B4 (JIS) Rotated"}
80 {$tmp2 = "B5 (JIS) Rotated"}
81 {$tmp2 = "Japanese Postcard Rotated"}
82 {$tmp2 = "Double Japanese Postcard Rotated"}
83 {$tmp2 = "A6 Rotated"}
84 {$tmp2 = "Japanese Envelope Kaku #2 Rotated"}
85 {$tmp2 = "Japanese Envelope Kaku #3 Rotated"}
86 {$tmp2 = "Japanese Envelope Chou #3 Rotated"}
87 {$tmp2 = "Japanese Envelope Chou #4 Rotated"}
88 {$tmp2 = "B6 (JIS)"}
89 {$tmp2 = "B6 (JIS) Rotated"}
90 {$tmp2 = "12X11"}
91 {$tmp2 = "Japanese Envelope You #4"}
92 {$tmp2 = "Japanese Envelope You #4 Rotated"}
93 {$tmp2 = "PRC 16K"}
94 {$tmp2 = "PRC 32K"}
95 {$tmp2 = "PRC 32K(Big)"}
96 {$tmp2 = "PRC Envelope #1"}
97 {$tmp2 = "PRC Envelope #2"}
98 {$tmp2 = "PRC Envelope #3"}
99 {$tmp2 = "PRC Envelope #4"}
100 {$tmp2 = "PRC Envelope #5"}
101 {$tmp2 = "PRC Envelope #6"}
102 {$tmp2 = "PRC Envelope #7"}
103 {$tmp2 = "PRC Envelope #8"}
104 {$tmp2 = "PRC Envelope #9"}
105 {$tmp2 = "PRC Envelope #10"}
106 {$tmp2 = "PRC 16K Rotated"}
107 {$tmp2 = "PRC 32K Rotated"}
108 {$tmp2 = "PRC 32K(Big) Rotated"}
109 {$tmp2 = "PRC Envelope #1 Rotated"}
110 {$tmp2 = "PRC Envelope #2 Rotated"}
111 {$tmp2 = "PRC Envelope #3 Rotated"}
112 {$tmp2 = "PRC Envelope #4 Rotated"}
113 {$tmp2 = "PRC Envelope #5 Rotated"}
114 {$tmp2 = "PRC Envelope #6 Rotated"}
115 {$tmp2 = "PRC Envelope #7 Rotated"}
116 {$tmp2 = "PRC Envelope #8 Rotated"}
117 {$tmp2 = "PRC Envelope #9 Rotated"}
Default {$tmp2 = "Paper Size could not be determined:
$($xelement)"}
}
$ReturnStr = "$txt $tmp2"
}
}
"form"
{
If($xtable)
{
$txt="Form Name:"
}
Else
{
$txt="Form Name`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
If($tmp2.length -gt 0)
{
$ReturnStr = "$txt $tmp2"
}
}
}
"true"
{
If($xtable)
{
$txt="TrueType:"
}
Else
{
$txt="TrueType`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp1 = $xelement.SubString($index + 1)
Switch ($tmp1)
{
1 {$tmp2 = "Bitmap"}
2 {$tmp2 = "Download"}
3 {$tmp2 = "Substitute"}
4 {$tmp2 = "Outline"}
Default {$tmp2 = "TrueType could not be determined: $
($xelement)"}
}
}
$ReturnStr = "$txt $tmp2"
}
"mode"
{
If($xtable)
{
$txt="Printer Model:"
}
Else
{
$txt="Printer Model`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
$ReturnStr = "$txt $tmp2"
}
}
"loca"
{
If($xtable)
{
$txt="Location:"
}
Else
{
$txt="Location`t:"
}
$index = $xelement.SubString(0).IndexOf('=')
if($index -ge 0)
{
$tmp2 = $xelement.SubString($index + 1)
If($tmp2.length -gt 0)
{
$ReturnStr = "$txt $tmp2"
}
}
}
Default {$ReturnStr = "Session printer setting could not be determined:
$($xelement)"}
}
Return $ReturnStr
}
Function AbortScript
{
$Script:Word.quit()
Write-Verbose "$(Get-Date): System Cleanup"
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Script:Word) |
Out-Null
If(Test-Path variable:global:word)
{
Remove-Variable -Name word -Scope Global 4>$Null
}
[gc]::collect()
[gc]::WaitForPendingFinalizers()
Write-Verbose "$(Get-Date): Script has been aborted"
$ErrorActionPreference = $SaveEAPreference
Exit
}
Function FindWordDocumentEnd
{
#return focus to main document
$Script:Doc.ActiveWindow.ActivePane.view.SeekView = $wdSeekMainDocument
#move to the end of the current document
$Script:Selection.EndKey($wdStory,$wdMove) | Out-Null
}
Function ProcessCitrixPolicies
{
Param([string]$xDriveName)
If(![String]::IsNullOrEmpty($Policy.Description))
{
WriteWordLine 0 1 "Description`t: "
$Policy.Description
}
WriteWordLine 0 1 "Enabled`t`t: " $Policy.Enabled
WriteWordLine 0 1 "Priority`t`t: " $Policy.Priority
Write-Verbose "$(Get-Date):
`t`t`tConnector for Configuration Manager 2012"
If((validStateProp $Setting
AdvanceWarningFrequency State ) -and ($Setting.AdvanceWarningFrequency.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Advance warning frequency interval: "
$tmp =
$Setting.AdvanceWarningFrequency.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
AdvanceWarningMessageBody State ) -and ($Setting.AdvanceWarningMessageBody.State
-ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Advance warning message box body text: "
$tmpArray =
$Setting.AdvanceWarningMessageBody.Value.Split("`n")
$tmp = ""
$cnt = 0
ForEach($Thing in $TmpArray)
{
If($Null -eq $Thing)
{
$Thing = ''
}
$cnt++
$tmp = "$($Thing) "
If($cnt -eq 1)
{
If($MSWord -or $PDF)
{
WriteWordLine 0 2
$txt ""
WriteWordLine 0 3
"" $tmp
}
}
Else
{
If($MSWord -or $PDF)
{
WriteWordLine 0 3
$txt $tmp
}
}
$txt = ""
}
$TmpArray = $Null
$tmp = $Null
}
If((validStateProp $Setting
AdvanceWarningMessageTitle State ) -and ($Setting.AdvanceWarningMessageTitle.State
-ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Advance warning message box title: "
$tmp =
$Setting.AdvanceWarningMessageTitle.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
AdvanceWarningPeriod State ) -and ($Setting.AdvanceWarningPeriod.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Advance warning time period: "
$tmp =
$Setting.AdvanceWarningPeriod.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
PvsImageUpdateDeadlinePeriod State ) -and
($Setting.PvsImageUpdateDeadlinePeriod.State -ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Deadline calculation time for newly available PVS images: "
$tmp =
$Setting.PvsImageUpdateDeadlinePeriod.Value
WriteWordLine 0 2 $txt $tmp
}
If((validStateProp $Setting
FinalForceLogoffMessageBody State ) -and
($Setting.FinalForceLogoffMessageBody.State -ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Final force logoff message box body text: "
$tmpArray =
$Setting.FinalForceLogoffMessageBody.Value.Split("`n")
$tmp = ""
$cnt = 0
ForEach($Thing in $TmpArray)
{
If($Null -eq $Thing)
{
$Thing = ''
}
$cnt++
$tmp = "$($Thing) "
If($cnt -eq 1)
{
WriteWordLine 0 2 $txt
""
WriteWordLine 0 3 ""
$tmp
}
Else
{
WriteWordLine 0 3 $txt
$tmp
}
$txt = ""
}
$TmpArray = $Null
$tmp = $Null
}
If((validStateProp $Setting
FinalForceLogoffMessageTitle State ) -and
($Setting.FinalForceLogoffMessageTitle.State -ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Final force logoff message box title: "
$tmp =
$Setting.FinalForceLogoffMessageTitle.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
ForceLogoffGracePeriod State ) -and ($Setting.ForceLogoffGracePeriod.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Force logoff grace period: "
$tmp =
$Setting.ForceLogoffGracePeriod.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
ForceLogoffMessageBody State ) -and ($Setting.ForceLogoffMessageBody.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Force logoff message box body text: "
$tmpArray =
$Setting.ForceLogoffMessageBody.Value.Split("`n")
$tmp = ""
$cnt = 0
ForEach($Thing in $TmpArray)
{
If($Null -eq $Thing)
{
$Thing = ''
}
$cnt++
$tmp = "$($Thing) "
If($cnt -eq 1)
{
WriteWordLine 0 2 $txt
""
WriteWordLine 0 3 ""
$tmp
}
Else
{
WriteWordLine 0 3 $txt
$tmp
}
$txt = ""
}
$TmpArray = $Null
$tmp = $Null
}
If((validStateProp $Setting
ForceLogoffMessageTitle State ) -and ($Setting.ForceLogoffMessageTitle.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Force logoff message box title: "
$tmp =
$Setting.ForceLogoffMessageTitle.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
ImageProviderIntegrationEnabled State ) -and
($Setting.ImageProviderIntegrationEnabled.State -ne "NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\PVS Integration enabled: "
$tmp =
$Setting.ImageProviderIntegrationEnabled.State
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
RebootMessageBody State ) -and ($Setting.RebootMessageBody.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Reboot message box body text: "
$tmp =
$Setting.RebootMessageBody.Value
WriteWordLine 0 2 $txt ""
WriteWordLine 0 3 "" $tmp
}
If((validStateProp $Setting
AgentTaskInterval State ) -and ($Setting.AgentTaskInterval.State -ne
"NotConfigured"))
{
$txt = "Connector for Configuration
Manager 2012\Regular time interval at which the agent task is to run: "
$tmp =
$Setting.AgentTaskInterval.Value
WriteWordLine 0 2 $txt $tmp
}
Switch
($Setting.DisplayDegradePreference.Value)
{
"ColorDepth" {WriteWordLine 0
3 "Degrade color depth first"}
"Resolution" {WriteWordLine 0
3 "Degrade resolution first"}
Default {WriteWordLine 0 3
"Display mode degrade preference could not be determined: $
($Setting.DisplayDegradePreference.Value)"}
}
}
If($Setting.DynamicPreview.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Graphics\Dynamic Windows Preview: " $Setting.DynamicPreview.State
}
If($Setting.ImageCaching.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Graphics\Image caching: " $Setting.ImageCaching.State
}
If($Setting.MaximumColorDepth.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Graphics\Maximum allowed color depth: "
Switch
($Setting.MaximumColorDepth.Value)
{
"BitsPerPixel8"
{WriteWordLine 0 3 "8 Bits Per Pixel"}
"BitsPerPixel15"
{WriteWordLine 0 3 "15 Bits Per Pixel"}
"BitsPerPixel16"
{WriteWordLine 0 3 "16 Bits Per Pixel"}
"BitsPerPixel24"
{WriteWordLine 0 3 "24 Bits Per Pixel"}
"BitsPerPixel32"
{WriteWordLine 0 3 "32 Bits Per Pixel"}
Default {WriteWordLine 0 3
"Maximum allowed color depth could not be determined: $
($Setting.MaximumColorDepth.Value)"}
}
}
If($Setting.MultimediaAccelerationDefaultBufferSize.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Multimedia\Windows Media Redirection Buffer Size (seconds): "
$Setting.MultimediaAccelerationDefaultBufferSize.Value
}
If($Setting.MultimediaAccelerationUseDefaultBufferSize.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Multimedia\Windows Media Redirection Buffer Size Use: "
$Setting.MultimediaAccelerationUseDefaultBufferSize.State
}
If($Setting.MultiPortPolicy.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\MultiStream
Connections\Multi-Port Policy: "
WriteWordLine 0 3 "CGP default
port" -nonewline
WriteWordLine 0 1 "priority: High"
[string]$Tmp =
$Setting.MultiPortPolicy.Value
If($Tmp.Length -gt 0)
{
[string]$cgpport1 =
$Tmp.substring(0, $Tmp.indexof(";"))
[string]$cgpport2 =
$Tmp.substring($cgpport1.length + 1 , $Tmp.indexof(";"))
[string]$cgpport3 =
$Tmp.substring((($cgpport1.length + 1)+($cgpport2.length + 1)) , $Tmp.indexof(";"))
[string]$cgpport1priority =
multiportpolicypriority $cgpport1.substring($cgpport1.length -1, 1)
[string]$cgpport2priority =
multiportpolicypriority $cgpport2.substring($cgpport2.length -1, 1)
[string]$cgpport3priority =
multiportpolicypriority $cgpport3.substring($cgpport3.length -1, 1)
$cgpport1 =
$cgpport1.substring(0, $cgpport1.indexof(","))
$cgpport2 =
$cgpport2.substring(0, $cgpport2.indexof(","))
$cgpport3 =
$cgpport3.substring(0, $cgpport3.indexof(","))
WriteWordLine 0 3 "CGP port1:
" $cgpport1 -nonewline
WriteWordLine 0 1 "priority:
" -nonewline
Switch ($cgpport1priority[0])
{
"V" {WriteWordLine 0 0
"Very High"}
"M" {WriteWordLine 0 0
"Medium"}
"L" {WriteWordLine 0 0
"Low"}
Default
{WriteWordLine 0 0 "Unknown"}
}
WriteWordLine 0 3 "CGP port2:
" $cgpport2 -nonewline
WriteWordLine 0 1 "priority:
" -nonewline
Switch ($cgpport2priority[0])
{
"V" {WriteWordLine 0 0
"Very High"}
"M" {WriteWordLine 0 0
"Medium"}
"L" {WriteWordLine 0 0
"Low"}
Default
{WriteWordLine 0 0 "Unknown"}
}
WriteWordLine 0 3 "CGP port3:
" $cgpport3 -nonewline
WriteWordLine 0 1 "priority:
" -nonewline
Switch ($cgpport3priority[0])
{
"V" {WriteWordLine 0 0
"Very High"}
"M" {WriteWordLine 0 0
"Medium"}
"L" {WriteWordLine 0 0
"Low"}
Default
{WriteWordLine 0 0 "Unknown"}
}
$cgpport1 = $Null
$cgpport2 = $Null
$cgpport3 = $Null
$cgpport1priority = $Null
$cgpport2priority = $Null
$cgpport3priority = $Null
}
$Tmp = $Null
}
If($Setting.MultiStreamPolicy.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\MultiStream
Connections\Multi-Stream: " $Setting.MultiStreamPolicy.State
}
If($Setting.PromptForPassword.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Security\Prompt for password: " $Setting.PromptForPassword.State
}
If($Setting.IdleTimerInterval.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Server
Limits\Server idle timer interval (milliseconds): "
$Setting.IdleTimerInterval.Value
}
$Table.Borders.InsideLineStyle = $wdLineStyleNone
$Table.Borders.OutsideLineStyle = $wdLineStyleNone
[int]$xRow = 1
$Table.Cell($xRow,1).Range.Text = "Name"
$Table.Cell($xRow,2).Range.Text = $test.name
$xRow++
$Table.Cell($xRow,2).Range.Text = $test.file
If($test.HasAttribute("arguments"))
{
$xRow++
$Table.Cell($xRow,1).Range.Text = "Arguments"
$Table.Cell($xRow,2).Range.Text = $test.arguments
}
If(!
[String]::IsNullOrEmpty($test.Description))
{
$xRow++
$Table.Cell($xRow,1).Range.Text = "Description"
$Table.Cell($xRow,2).Range.Text = $test.description
}
$xRow++
$Table.Cell($xRow,1).Range.Text = "Interval"
$Table.Cell($xRow,2).Range.Text = $test.interval
$xRow++
$Table.Cell($xRow,1).Range.Text = "Time-out"
$Table.Cell($xRow,2).Range.Text = $test.timeout
$xRow++
$Table.Cell($xRow,1).Range.Text = "Threshold"
$Table.Cell($xRow,2).Range.Text = $test.threshold
$xRow++
$Table.Rows.SetLeftIndent($Indent3TabStops,$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
}
$XML = $Null
$xRow = $Null
$Columns = $Null
$Row = $Null
}
If($Setting.FlashServerSideContentFetchingWhitelist.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Adobe Flash
Delivery\Flash Redirection\Flash server-side content fetching "
WriteWordLine 0 3 "URL list: "
$Values =
$Setting.FlashServerSideContentFetchingWhitelist.Values
ForEach($Value in $Values)
{
WriteWordLine 0 4 $Value
}
$Values = $Null
}
$Table.Rows.First.Shading.BackgroundPatternColor = $wdColorGray15
$Table.Cell($xRow,1).Range.Font.Bold = $True
$Table.Cell($xRow,1).Range.Text =
"Action"
$Table.Cell($xRow,2).Range.Font.Bold = $True
$Table.Cell($xRow,2).Range.Text =
"URL Pattern"
$Table.Cell($xRow,3).Range.Font.Bold = $True
$Table.Cell($xRow,3).Range.Text =
"Flash Instance"
ForEach($Value in $Values)
{
$Items = $Value.Split(' ')
$xRow++
Write-Verbose "$(Get-Date):
`t`t`t`t`t`tProcessing row for $($Value)"
$Action = $Items[0]
If($Action -eq "CLIENT")
{
$Action = "Render On
Client"
}
ElseIf($Action -eq "SERVER")
{
$Action = "Render On
Server"
}
ElseIf($Action -eq "BLOCK")
{
$Action = "BLOCK
"
}
$Url = $Items[1]
If($Items.Count -eq 3)
{
$FlashInstance =
$Items[2]
}
Else
{
$FlashInstance = ""
}
$Table.Cell($xRow,1).Range.Text = $Action
$Table.Cell($xRow,2).Range.Text = $Url
$Table.Cell($xRow,3).Range.Text = $FlashInstance
}
$Table.Rows.SetLeftIndent($Indent3TabStops,$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
$Values = $Null
$Action = $Null
$Url = $Null
$FlashInstance = $Null
$Spc = $Null
}
If($Setting.AllowSpeedFlash.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Adobe Flash
Delivery\Legacy Server Side Optimizations\"
WriteWordLine 0 3 "Flash quality
adjustment: "
Switch
($Setting.AllowSpeedFlash.Value)
{
"NoOptimization"
{WriteWordLine 0 3 "Do not optimize Flash animation options"}
"AllConnections"
{WriteWordLine 0 3 "Optimize Flash animation options for all connections"}
"RestrictedBandwidth"
{WriteWordLine 0 3 "Optimize Flash animation options for low bandwidth connections
only"}
Default {WriteWordLine 0 3
"Flash quality adjustment could not be determined: $
($Setting.AllowSpeedFlash.Value)"}
}
}
Write-Verbose "$(Get-Date):
`t`t`tICA\Audio"
If($Setting.AudioPlugNPlay.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Audio\Audio
Plug N Play: " $Setting.AudioPlugNPlay.State
}
If($Setting.AudioQuality.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Audio\Audio
quality: "
Switch
($Setting.AudioQuality.Value)
{
"Low" {WriteWordLine 0 3
"Low - for low-speed connections"}
"Medium" {WriteWordLine 0 3
"Medium - optimized for speech"}
"High" {WriteWordLine 0 3
"High - high definition audio"}
Default {WriteWordLine 0 3
"Audio quality could not be determined: $($Setting.AudioQuality.Value)"}
}
}
If($Setting.ClientAudioRedirection.State
-ne "NotConfigured")
{
WriteWordLine 0 2 "ICA\Audio\Client
audio redirection: " $Setting.ClientAudioRedirection.State
}
If($Setting.MicrophoneRedirection.State
-ne "NotConfigured")
{
WriteWordLine 0 2 "ICA\Audio\Client
microphone redirection: " $Setting.MicrophoneRedirection.State
}
Write-Verbose "$(Get-Date):
`t`t`tICA\Bandwidth"
If($Setting.AudioBandwidthLimit.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Bandwidth\Audio redirection bandwidth limit (Kbps): "
$Setting.AudioBandwidthLimit.Value
}
If($Setting.AudioBandwidthPercent.State
-ne "NotConfigured")
{
WriteWordLine 0 2
"ICA\Bandwidth\Audio redirection bandwidth limit %: "
$Setting.AudioBandwidthPercent.Value
}
If($Setting.USBBandwidthLimit.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Bandwidth\Client USB device redirection bandwidth limit: "
$Setting.USBBandwidthLimit.Value
}
If($Setting.USBBandwidthPercent.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Bandwidth\Client USB device redirection bandwidth limit %: "
$Setting.USBBandwidthPercent.Value
}
If($Setting.ClipboardBandwidthLimit.State
-ne "NotConfigured")
{
WriteWordLine 0 2
"ICA\Bandwidth\Clipboard redirection bandwidth limit (Kbps): "
$Setting.ClipboardBandwidthLimit.Value
}
WriteWordLine 0 3 $PrtString
}
$tmp = $Null
$PrtString = $Null
}
}
WriteWordLine 0 0 ""
}
$valArray = $Null
$prArray = $Null
}
$Table.Rows.First.Shading.BackgroundPatternColor = $wdColorGray15
$Table.Cell($xRow,1).Range.Font.Bold = $True
$Table.Cell($xRow,1).Range.Text =
"Driver Name"
$Table.Cell($xRow,2).Range.Font.Bold = $True
$Table.Cell($xRow,2).Range.Text =
"Action"
$Table.Cell($xRow,3).Range.Font.Bold = $True
$Table.Cell($xRow,3).Range.Text =
"Settings"
$Table.Cell($xRow,4).Range.Font.Bold = $True
$Table.Cell($xRow,4).Range.Text =
"Server Driver"
ForEach($element in $array)
{
#WriteWordLine 0 3 $element
$Items = $element.Split(',')
$xRow++
Write-Verbose "$(Get-Date):
`t`t`t`t`t`tProcessing row for $($Items[0])"
$DriverName = $Items[0]
$Action = $Items[1]
If($Action -match 'Replace=')
{
$ServerDriver =
$Action.substring($Action.indexof("=")+1)
$Action = "Replace"
}
Else
{
$ServerDriver = ""
If($Action -eq "Allow")
{
$Action = "Allow"
}
ElseIf($Action -eq
"Deny")
{
$Action = "Do not
create"
}
ElseIf($Action -eq
"UPD_Only")
{
$Action = "Create
with universal driver"
}
}
If($Items.count -gt 2)
{
$PrtSettings = ""
[int]$BeginAt = 2
[int]$EndAt =
$Items.count
for ($i=$BeginAt;$i -lt
$EndAt; $i++)
{
$tmp =
$Items[$i].SubString(0, 4)
$tmp1 = Get-
PrinterModifiedSettings $tmp $Items[$i] $True
If(!
[String]::IsNullOrEmpty($tmp1))
{
$PrtSettings
+= ($tmp1 + "`n")
}
}
}
Else
{
$PrtSettings =
"Unmodified"
}
$Table.Cell($xRow,1).Range.Text = $DriverName
$Table.Cell($xRow,2).Range.Text = $Action
$Table.Cell($xRow,3).Range.Text = $PrtSettings
$Table.Cell($xRow,4).Range.Text = $ServerDriver
}
$array = $Null
$Table.Rows.SetLeftIndent($Indent3TabStops,$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
WriteWordLine 0 0 ""
}
Switch($TestSetting)
{
"StandardQua
lity" {$TxtSetting = "Standard quality"}
"BestQuality
" {$TxtSetting = "Best quality (lossless compression)"}
"HighQuality
" {$TxtSetting = "High quality"}
"ReducedQual
ity" {$TxtSetting = "Reduced quality (maximum compression)"}
}
}
"HeavyweightCompression"
{
$TxtLabel =
"Enable heavyweight compression:"
If($TestSetting
-eq "True")
{
$TxtSetting
= "Yes"
}
Else
{
$TxtSetting
= "No"
}
}
"ImageCaching"
{
$TxtLabel = "Allow
caching of embedded images:"
If($TestSetting
-eq "True")
{
$TxtSetting
= "Yes"
}
Else
{
$TxtSetting
= "No"
}
}
"FontCaching"
{
$TxtLabel = "Allow
caching of embedded fonts:"
If($TestSetting
-eq "True")
{
$TxtSetting
= "Yes"
}
Else
{
$TxtSetting
= "No"
}
}
"AllowNonAdminsToModify"
{
$TxtLabel = "Allow
non-administrators to modify these settings:"
If($TestSetting
-eq "True")
{
$TxtSetting
= "Yes"
}
Else
{
$TxtSetting
= "No"
}
}
}
WriteWordLine 0 3 "$TxtLabel
$TxtSetting"
}
$TmpArray = $Null
}
#0x05/NT/WEBSTERSLAB\ADMINISTRATOR/S-1-5-21-3679396586-1061193519-2853834051-
500 (domain user)
#0x05/NT/WEBSTERSLAB\DOMAIN
ADMINS/S-1-5-21-3679396586-1061193519-2853834051-512 (domain group)
#we only need the computer\account
or domain\account
#first 9 characters are 0x05/NT/
for all account types
#since PoSH starts counting at 0 we
don't need the first 9 characters
#Then we need the position of the
first / after the computer\account
#what is left between the two is
what we need
ForEach($element in $array)
{
$x = $element.indexof("/",8)
$tmp =
$element.substring(8,$x-8)
WriteWordLine 0 3 $tmp
}
$array = $Null
$x = $Null
$tmp = $Null
}
If($Setting.ShadowDenyList.State -ne
"NotConfigured")
{
WriteWordLine 0 2
"ICA\Shadowing\Users who cannot shadow other users: "
$array =
$Setting.ShadowDenyList.Values
ForEach($element in $array)
{
$x = $element.indexof("/",8)
$tmp =
$element.substring(8,$x-8)
WriteWordLine 0 3 $tmp
}
$array = $Null
$x = $Null
$tmp = $Null
}
Write-Verbose "$(Get-Date):
`t`t`tICA\Time Zone Control"
If($Setting.LocalTimeEstimation.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Time Zone
Control\Estimate local time for legacy clients: "
$Setting.LocalTimeEstimation.State
}
If($Setting.SessionTimeZone.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\Time Zone
Control\Use local time of client: "
Switch
($Setting.SessionTimeZone.Value)
{
"UseServerTimeZone"
{WriteWordLine 0 3 "Use server time zone"}
"UseClientTimeZone"
{WriteWordLine 0 3 "Use client time zone"}
Default {WriteWordLine 0 3
"Use local time of client could not be determined: $
($Setting.SessionTimeZone.Value)"}
}
}
Write-Verbose "$(Get-Date):
`t`t`tICA\TWAIN devices"
If($Setting.TwainRedirection.State -ne
"NotConfigured")
{
WriteWordLine 0 2 "ICA\TWAIN
devices\Client TWAIN device redirection: " $Setting.TwainRedirection.State
}
If($Setting.TwainCompressionLevel.State
-ne "NotConfigured")
{
WriteWordLine 0 2 "ICA\TWAIN
devices\TWAIN compression level: "
Switch
($Setting.TwainCompressionLevel.Value)
{
"None" {WriteWordLine 0 3
"None"}
"Low" {WriteWordLine 0 3
"Low"}
"Medium" {WriteWordLine 0 3
"Medium"}
"High" {WriteWordLine 0 3
"High"}
Default {WriteWordLine 0 3
"TWAIN compression level could not be determined: $
($Setting.TwainCompressionLevel.Value)"}
}
}
Write-Verbose "$(Get-Date): `t`t`tICA\USB
devices"
If($Setting.UsbDeviceRedirection.State
-ne "NotConfigured")
{
WriteWordLine 0 2 "ICA\USB
devices\Client USB device redirection: " $Setting.UsbDeviceRedirection.State
}
$Policies = $Null
If($xDriveName -ne "")
{
Write-Verbose "$(Get-Date): `tRemoving ADGpoDrv PSDrive"
Remove-PSDrive ADGpoDrv -EA 0 4>$Null
Write-Verbose "$(Get-Date): "
}
}
Function GetCtxGPOsInAD
{
#thanks to the Citrix Engineering Team for pointers and for Michael B. Smith
for creating the function
#updated 07-Nov-13 to work in a Windows Workgroup environment
Write-Verbose "$(Get-Date): Testing for an Active Directory environment"
$root = [ADSI]"LDAP://RootDSE"
If([String]::IsNullOrEmpty($root.PSBase.Name))
{
Write-Verbose "$(Get-Date): Not in an Active Directory environment"
$root = $Null
$xArray = @()
}
Else
{
Write-Verbose "$(Get-Date): In an Active Directory environment"
$domainNC = $root.defaultNamingContext.ToString()
$root = $Null
$xArray = @()
Function BuildTableForServerOrWG
{
Param([Array]$xArray, [String]$xType)
#added a second parameter to the function so the verbose message would say
whether
#the function is processing servers, security groups or OUs.
FindWordDocumentEnd
$xArray = $Null
}
<#
.Synopsis
Add a table to a Microsoft Word document
.DESCRIPTION
This function adds a table to a Microsoft Word document from either an array
of
Hashtables or an array of PSCustomObjects.
Using this function is quicker than setting each table cell individually but
can
only utilise the built-in MS Word table autoformats. Individual tables cells
can
be altered after the table has been appended to the document (a table
reference
is returned).
.EXAMPLE
AddWordTable -Hashtable $HashtableArray
This example adds table to the MS Word document, utilising all key/value
pairs in
the array of hashtables. Column headers will display the key names as
defined.
Note: the columns might not be displayed in the order that they were defined.
To
ensure columns are displayed in the required order utilise the -Columns
parameter.
.EXAMPLE
AddWordTable -Hashtable $HashtableArray -List
This example adds table to the MS Word document, utilising all key/value
pairs in
the array of hashtables. No column headers will be added, in a ListView
format.
Note: the columns might not be displayed in the order that they were defined.
To
ensure columns are displayed in the required order utilise the -Columns
parameter.
.EXAMPLE
AddWordTable -CustomObject $PSCustomObjectArray
This example adds table to the MS Word document, utilising all note property
names
the array of PSCustomObjects. Column headers will display the note property
names.
Note: the columns might not be displayed in the order that they were defined.
To
ensure columns are displayed in the required order utilise the -Columns
parameter.
.EXAMPLE
AddWordTable -Hashtable $HashtableArray -Columns
FirstName,LastName,EmailAddress
This example adds a table to the MS Word document, but only using the
specified
key names: FirstName, LastName and EmailAddress. If other keys are present in
the
array of Hashtables they will be ignored.
.EXAMPLE
AddWordTable -CustomObject $PSCustomObjectArray -Columns
FirstName,LastName,EmailAddress -Headers "First Name","Last Name","Email Address"
This example adds a table to the MS Word document, but only using the
specified
PSCustomObject note properties: FirstName, LastName and EmailAddress. If
other note
properties are present in the array of PSCustomObjects they will be ignored.
The
display names for each specified column header has been overridden to display
a
custom header. Note: the order of the header names must match the specified
columns.
#>
Function AddWordTable
{
[CmdletBinding()]
Param
(
# Array of Hashtable (including table headers)
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,
ParameterSetName='Hashtable', Position=0)]
[ValidateNotNullOrEmpty()] [System.Collections.Hashtable[]] $Hashtable,
# Array of PSCustomObjects
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,
ParameterSetName='CustomObject', Position=0)]
[ValidateNotNullOrEmpty()] [PSCustomObject[]] $CustomObject,
# Array of Hashtable key names or PSCustomObject property names to
include, in display order.
# If not supplied then all Hashtable keys or all PSCustomObject
properties will be displayed.
[Parameter(ValueFromPipelineByPropertyName=$true)] [AllowNull()]
[string[]] $Columns = $null,
# Array of custom table header strings in display order.
[Parameter(ValueFromPipelineByPropertyName=$true)] [AllowNull()]
[string[]] $Headers = $null,
# AutoFit table behavior.
[Parameter(ValueFromPipelineByPropertyName=$true)] [AllowNull()] [int]
$AutoFit = -1,
# List view (no headers)
[Switch] $List,
# Grid lines
[Switch] $NoGridLines,
# Built-in Word table formatting style constant
# Would recommend only $wdTableFormatContempory for normal usage
(possibly $wdTableFormatList5 for List view)
[Parameter(ValueFromPipelineByPropertyName=$true)] [int] $Format = 0
)
Begin
{
Write-Debug ("Using parameter set '{0}'" -f
$PSCmdlet.ParameterSetName);
## Check if -Columns wasn't specified but -Headers were (saves some
additional parameter sets!)
If(($Columns -eq $null) -and ($Headers -ne $null))
{
Write-Warning "No columns specified and therefore, specified
headers will be ignored.";
$Columns = $null;
}
ElseIf(($Columns -ne $null) -and ($Headers -ne $null))
{
## Check if number of specified -Columns matches number of
specified -Headers
If($Columns.Length -ne $Headers.Length)
{
Write-Error "The specified number of columns does not match
the specified number of headers.";
}
} ## end elseif
} ## end Begin
Process
{
## Build the Word table data string to be converted to a range and then
a table later.
[System.Text.StringBuilder] $WordRangeString = New-Object
System.Text.StringBuilder;
Switch ($PSCmdlet.ParameterSetName)
{
'CustomObject'
{
If($Columns -eq $null)
{
## Build the available columns from all availble
PSCustomObject note properties
[string[]] $Columns = @();
## Add each NoteProperty name to the array
ForEach($Property in ($CustomObject | Get-Member
-MemberType NoteProperty))
{
$Columns += $Property.Name;
}
}
Default
{ ## Hashtable
If($Columns -eq $null)
{
## Build the available columns from all available
hashtable keys. Hopefully
## all Hashtables have the same keys (they should for
a table).
$Columns = $Hashtable[0].Keys;
}
#the next line causes the heading row to flow across page breaks
$WordTable.Rows.First.Headingformat = $wdHeadingFormatTrue;
If(!$NoGridLines)
{
$WordTable.Borders.InsideLineStyle = $wdLineStyleSingle;
$WordTable.Borders.OutsideLineStyle = $wdLineStyleSingle;
}
Return $WordTable;
} ## end Process
}
<#
.Synopsis
Sets the format of one or more Word table cells
.DESCRIPTION
This function sets the format of one or more table cells, either from a
collection
of Word COM object cell references, an individual Word COM object cell
reference or
a hashtable containing Row and Column information.
The font name, font size, bold, italic , underline and shading values can be
used.
.EXAMPLE
SetWordCellFormat -Hashtable $Coordinates -Table $TableReference -Bold
This example sets all text to bold that is contained within the
$TableReference
Word table, using an array of hashtables. Each hashtable contain a pair of
co-
ordinates that is used to select the required cells. Note: the hashtable must
contain the .Row and .Column key names. For example:
@ { Row = 7; Column = 3 } to set the cell at row 7 and column 3 to bold.
.EXAMPLE
$RowCollection = $Table.Rows.First.Cells
SetWordCellFormat -Collection $RowCollection -Bold -Size 10
This example sets all text to size 8 and bold for all cells that are
contained
within the first row of the table.
Note: the $Table.Rows.First.Cells returns a collection of Word COM cells
objects
that are in the first table row.
.EXAMPLE
$ColumnCollection = $Table.Columns.Item(2).Cells
SetWordCellFormat -Collection $ColumnCollection -BackgroundColor 255
This example sets the background (shading) of all cells in the table's second
column to red.
Note: the $Table.Columns.Item(2).Cells returns a collection of Word COM cells
objects
that are in the table's second column.
.EXAMPLE
SetWordCellFormat -Cell $Table.Cell(17,3) -Font "Tahoma" -Color 16711680
This example sets the font to Tahoma and the text color to blue for the cell
located
in the table's 17th row and 3rd column.
Note: the $Table.Cell(17,3) returns a single Word COM cells object.
#>
Function SetWordCellFormat
{
[CmdletBinding(DefaultParameterSetName='Collection')]
Param (
# Word COM object cell collection reference
[Parameter(Mandatory=$true, ValueFromPipeline=$true,
ParameterSetName='Collection', Position=0)] [ValidateNotNullOrEmpty()] $Collection,
# Word COM object individual cell reference
[Parameter(Mandatory=$true, ParameterSetName='Cell', Position=0)]
[ValidateNotNullOrEmpty()] $Cell,
# Hashtable of cell co-ordinates
[Parameter(Mandatory=$true, ParameterSetName='Hashtable', Position=0)]
[ValidateNotNullOrEmpty()] [System.Collections.Hashtable[]] $Coordinates,
# Word COM object table reference
[Parameter(Mandatory=$true, ParameterSetName='Hashtable', Position=1)]
[ValidateNotNullOrEmpty()] $Table,
# Font name
[Parameter()] [AllowNull()] [string] $Font = $null,
# Font color
[Parameter()] [AllowNull()] $Color = $null,
# Font size
[Parameter()] [ValidateNotNullOrEmpty()] [int] $Size = 0,
# Cell background color
[Parameter()] [AllowNull()] $BackgroundColor = $null,
# Force solid background color
[Switch] $Solid,
[Switch] $Bold,
[Switch] $Italic,
[Switch] $Underline
)
Begin
{
Write-Debug ("Using parameter set '{0}'." -f
$PSCmdlet.ParameterSetName);
}
Process
{
Switch ($PSCmdlet.ParameterSetName)
{
'Collection' {
ForEach($Cell in $Collection)
{
If($BackgroundColor -ne $null)
{ $Cell.Shading.BackgroundPatternColor = $BackgroundColor; }
If($Bold) { $Cell.Range.Font.Bold = $true; }
If($Italic) { $Cell.Range.Font.Italic = $true; }
If($Underline) { $Cell.Range.Font.Underline = 1; }
If($Font -ne $null) { $Cell.Range.Font.Name =
$Font; }
If($Color -ne $null) { $Cell.Range.Font.Color =
$Color; }
If($Size -ne 0) { $Cell.Range.Font.Size = $Size; }
If($Solid) { $Cell.Shading.Texture = 0; } ##
wdTextureNone
} # end foreach
} # end Collection
'Cell'
{
If($Bold) { $Cell.Range.Font.Bold = $true; }
If($Italic) { $Cell.Range.Font.Italic = $true; }
If($Underline) { $Cell.Range.Font.Underline = 1; }
If($Font -ne $null) { $Cell.Range.Font.Name = $Font; }
If($Color -ne $null) { $Cell.Range.Font.Color = $Color; }
If($Size -ne 0) { $Cell.Range.Font.Size = $Size; }
If($BackgroundColor -ne $null)
{ $Cell.Shading.BackgroundPatternColor = $BackgroundColor; }
If($Solid) { $Cell.Shading.Texture = 0; } ## wdTextureNone
} # end Cell
'Hashtable'
{
ForEach($Coordinate in $Coordinates)
{
$Cell = $Table.Cell($Coordinate.Row,
$Coordinate.Column);
If($Bold) { $Cell.Range.Font.Bold = $true; }
If($Italic) { $Cell.Range.Font.Italic = $true; }
If($Underline) { $Cell.Range.Font.Underline = 1; }
If($Font -ne $null) { $Cell.Range.Font.Name =
$Font; }
If($Color -ne $null) { $Cell.Range.Font.Color =
$Color; }
If($Size -ne 0) { $Cell.Range.Font.Size = $Size; }
If($BackgroundColor -ne $null)
{ $Cell.Shading.BackgroundPatternColor = $BackgroundColor; }
If($Solid) { $Cell.Shading.Texture = 0; } ##
wdTextureNone
}
} # end Hashtable
} # end switch
} # end process
}
<#
.Synopsis
Sets alternate row colors in a Word table
.DESCRIPTION
This function sets the format of alternate rows within a Word table using the
specified $BackgroundColor. This function is expensive (in performance terms)
as
it recursively sets the format on alternate rows. It would be better to pick
one
of the predefined table formats (if one exists)? Obviously the more rows, the
longer it takes :'(
This example sets every-other table (starting with the first) row and sets
the
background color to red (wdColorRed).
.EXAMPLE
SetWordTableAlternateRowColor -Table $TableReference -BackgroundColor 39423
-Seed Second
This example sets every other table (starting with the second) row and sets
the
background color to light orange (weColorLightOrange).
#>
Function SetWordTableAlternateRowColor
{
[CmdletBinding()]
Param (
# Word COM object table reference
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[ValidateNotNullOrEmpty()] $Table,
# Alternate row background color
[Parameter(Mandatory=$true, Position=1)] [ValidateNotNull()] [int]
$BackgroundColor,
# Alternate row starting seed
[Parameter(ValueFromPipelineByPropertyName=$true, Position=2)]
[ValidateSet('First','Second')] [string] $Seed = 'First'
)
Process
{
$StartDateTime = Get-Date;
Write-Debug ("{0}: `t`tSetting alternate table row colors.." -f
$StartDateTime);
## Determine the row seed (only really need to check for 'Second' and
default to 'First' otherwise
If($Seed.ToLower() -eq 'second')
{
$StartRowIndex = 2;
}
Else
{
$StartRowIndex = 1;
}
$Table.Rows.Item($AlternateRowIndex).Shading.BackgroundPatternColor =
$BackgroundColor;
}
## I've put verbose calls in here we can see how expensive this
functionality actually is.
$EndDateTime = Get-Date;
$ExecutionTime = New-TimeSpan -Start $StartDateTime -End $EndDateTime;
Write-Debug ("{0}: `t`tDone setting alternate row style color in '{1}'
seconds" -f $EndDateTime, $ExecutionTime.TotalSeconds);
}
}
Function ShowScriptOptions
{
Write-Verbose "$(Get-Date): "
Write-Verbose "$(Get-Date): "
Write-Verbose "$(Get-Date): Company Name : $($Script:CoName)"
Write-Verbose "$(Get-Date): Company Address : $($CompanyAddress)"
Write-Verbose "$(Get-Date): Company Email : $($CompanyEmail)"
Write-Verbose "$(Get-Date): Company Fax : $($CompanyFax)"
Write-Verbose "$(Get-Date): Company Phone : $($CompanyPhone)"
Write-Verbose "$(Get-Date): Cover Page : $($CoverPage)"
Write-Verbose "$(Get-Date): User Name : $($UserName)"
Write-Verbose "$(Get-Date): Save As PDF : $($PDF)"
Write-Verbose "$(Get-Date): Save As WORD : $($MSWORD)"
Write-Verbose "$(Get-Date): Add DateTime : $($AddDateTime)"
Write-Verbose "$(Get-Date): HW Inventory : $($Hardware)"
Write-Verbose "$(Get-Date): SW Inventory : $($Software)"
If(!$Summary)
{
Write-Verbose "$(Get-Date): Start Date : $($StartDate)"
Write-Verbose "$(Get-Date): End Date : $($EndDate)"
}
Write-Verbose "$(Get-Date): Section : $($Section)"
Write-Verbose "$(Get-Date): Summary : $($Summary)"
Write-Verbose "$(Get-Date): Filename1 : $($Script:FileName1)"
If($PDF)
{
Write-Verbose "$(Get-Date): Filename2 : $($Script:FileName2)"
}
Write-Verbose "$(Get-Date): OS Detected : $($Script:RunningOS)"
Write-Verbose "$(Get-Date): PSUICulture : $($PSUICulture)"
Write-Verbose "$(Get-Date): PSCulture : $($PSCulture)"
Write-Verbose "$(Get-Date): Word version : $($Script:WordProduct)"
Write-Verbose "$(Get-Date): Word language : $($Script:WordLanguageValue)"
Write-Verbose "$(Get-Date): PoSH version : $($Host.Version)"
Write-Verbose "$(Get-Date): "
Write-Verbose "$(Get-Date): Script start : $($Script:StartTime)"
Write-Verbose "$(Get-Date): "
Write-Verbose "$(Get-Date): "
}
Function SetupWord
{
Write-Verbose "$(Get-Date): Setting up Word"
SetWordHashTable $Script:WordCultureCode
[int]$Script:WordVersion = [int]$Script:Word.Version
If($Script:WordVersion -eq $wdWord2016)
{
$Script:WordProduct = "Word 2016"
}
ElseIf($Script:WordVersion -eq $wdWord2013)
{
$Script:WordProduct = "Word 2013"
}
ElseIf($Script:WordVersion -eq $wdWord2010)
{
$Script:WordProduct = "Word 2010"
}
ElseIf($Script:WordVersion -eq $wdWord2007)
{
$ErrorActionPreference = $SaveEAPreference
Write-Error "`n`n`t`tMicrosoft Word 2007 is no longer
supported.`n`n`t`tScript will end.`n`n"
AbortScript
}
Else
{
$ErrorActionPreference = $SaveEAPreference
Write-Error "`n`n`t`tYou are running an untested or unsupported version
of Microsoft Word.`n`n`t`tScript will end.`n`n`t`tPlease send info on your version
of Word to webster@carlwebster.com`n`n"
AbortScript
}
If([String]::IsNullOrEmpty($TmpName))
{
Write-Warning "`n`n`t`tCompany Name is blank so Cover Page will
not show a Company Name."
Write-Warning "`n`t`tCheck
HKCU:\Software\Microsoft\Office\Common\UserInfo for Company or CompanyName value."
Write-Warning "`n`t`tYou may want to use the -CompanyName
parameter if you need a Company Name on the cover page.`n`n"
}
Else
{
$Script:CoName = $TmpName
Write-Verbose "$(Get-Date): Updated company name to $
($Script:CoName)"
}
}
'da-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Sidelinje"
$CPChanged = $True
}
}
'de-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Randlinie"
$CPChanged = $True
}
}
'es-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Línea lateral"
$CPChanged = $True
}
}
'fi-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Sivussa"
$CPChanged = $True
}
}
'fr-' {
If($CoverPage -eq "Sideline")
{
If($Script:WordVersion -eq $wdWord2013 -or
$Script:WordVersion -eq $wdWord2016)
{
$CoverPage = "Lignes latérales"
$CPChanged = $True
}
Else
{
$CoverPage = "Ligne latérale"
$CPChanged = $True
}
}
}
'nb-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Sidelinje"
$CPChanged = $True
}
}
'nl-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Terzijde"
$CPChanged = $True
}
}
'pt-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Linha Lateral"
$CPChanged = $True
}
}
'sv-' {
If($CoverPage -eq "Sideline")
{
$CoverPage = "Sidlinje"
$CPChanged = $True
}
}
}
If($CPChanged)
{
Write-Verbose "$(Get-Date): Changed Default Cover Page from
Sideline to $($CoverPage)"
}
}
If(!$ValidCP)
{
$ErrorActionPreference = $SaveEAPreference
Write-Verbose "$(Get-Date): Word language value $
($Script:WordLanguageValue)"
Write-Verbose "$(Get-Date): Culture code $($Script:WordCultureCode)"
Write-Error "`n`n`t`tFor $($Script:WordProduct), $($CoverPage) is not a
valid Cover Page option.`n`n`t`tScript cannot continue.`n`n"
AbortScript
}
ShowScriptOptions
$Script:Word.Visible = $False
#http://jdhitsolutions.com/blog/2012/05/san-diego-2012-powershell-deep-dive-
slides-and-demos/
#using Jeff's Demo-WordReport.ps1 file for examples
Write-Verbose "$(Get-Date): Load Word Templates"
[bool]$Script:CoverPagesExist = $False
[bool]$BuildingBlocksExist = $False
$Script:Word.Templates.LoadBuildingBlocks()
#word 2010/2013
$BuildingBlocksCollection = $Script:Word.Templates | Where {$_.name -eq
"Built-In Building Blocks.dotx"}
$BuildingBlocksCollection |
ForEach{
If ($_.BuildingBlockEntries.Item($CoverPage).Name -eq $CoverPage)
{
$BuildingBlocks = $_
}
}
Try
{
$part = $BuildingBlocks.BuildingBlockEntries.Item($CoverPage)
}
Catch
{
$part = $Null
}
If(!$Script:CoverPagesExist)
{
Write-Verbose "$(Get-Date): Cover Pages are not installed or the Cover
Page $($CoverPage) does not exist."
Write-Warning "Cover Pages are not installed or the Cover Page $
($CoverPage) does not exist."
Write-Warning "This report will not have a Cover Page."
}
$Script:Selection = $Script:Word.Selection
If($Script:Selection -eq $Null)
{
Write-Verbose "$(Get-Date): "
$ErrorActionPreference = $SaveEAPreference
Write-Error "`n`n`t`tAn unknown error happened selecting the entire
Word document for default formatting options.`n`n`t`tScript cannot continue.`n`n"
AbortScript
}
#set Default tab stops to 1/2 inch (this line is not from Jeff Hicks)
#36 = .50"
$Script:Word.ActiveDocument.DefaultTabStop = 36
#Disable Spell and Grammar Check to resolve issue and improve performance
(from Pat Coughlin)
Write-Verbose "$(Get-Date): Disable grammar and spell checking"
#bug reported 1-Apr-2014 by Tim Mangan
#save current options first before turning them off
$Script:CurrentGrammarOption = $Script:Word.Options.CheckGrammarAsYouType
$Script:CurrentSpellingOption = $Script:Word.Options.CheckSpellingAsYouType
$Script:Word.Options.CheckGrammarAsYouType = $False
$Script:Word.Options.CheckSpellingAsYouType = $False
If($BuildingBlocksExist)
{
#insert new page, getting ready for table of contents
Write-Verbose "$(Get-Date): Insert new page, getting ready for table of
contents"
$part.Insert($Script:Selection.Range,$True) | Out-Null
$Script:Selection.InsertNewPage()
#table of contents
Write-Verbose "$(Get-Date): Table of Contents - $
($myHash.Word_TableOfContents)"
$toc =
$BuildingBlocks.BuildingBlockEntries.Item($myHash.Word_TableOfContents)
If($toc -eq $Null)
{
Write-Verbose "$(Get-Date): "
Write-Verbose "$(Get-Date): Table of Content - $
($myHash.Word_TableOfContents) could not be retrieved."
Write-Warning "This report will not have a Table of Contents."
}
Else
{
$toc.insert($Script:Selection.Range,$True) | Out-Null
}
}
Else
{
Write-Verbose "$(Get-Date): Table of Contents are not installed."
Write-Warning "Table of Contents are not installed so this report will
not have a Table of Contents."
}
FindWordDocumentEnd
Write-Verbose "$(Get-Date):"
#end of Jeff Hicks
}
Function UpdateDocumentProperties
{
Param([string]$AbstractTitle, [string]$SubjectTitle)
#updated 8-Jun-2017 with additional cover page fields
#Update document properties
If($MSWORD -or $PDF)
{
If($Script:CoverPagesExist)
{
Write-Verbose "$(Get-Date): Set Cover Page Properties"
#8-Jun-2017 put these 4 items in alpha order
Set-DocumentProperty -Document $Script:Doc -DocProperty Author -Value
$UserName
Set-DocumentProperty -Document $Script:Doc -DocProperty Company -Value
$Script:CoName
Set-DocumentProperty -Document $Script:Doc -DocProperty Subject -Value
$SubjectTitle
Set-DocumentProperty -Document $Script:Doc -DocProperty Title -Value
$Script:title
#added 8-Jun-2017
$ab = $cp.documentelement.ChildNodes | Where {$_.basename -eq
"CompanyAddress"}
#set the text
[string]$abstract = $CompanyAddress
$ab.Text = $abstract
#added 8-Jun-2017
$ab = $cp.documentelement.ChildNodes | Where {$_.basename -eq
"CompanyEmail"}
#set the text
[string]$abstract = $CompanyEmail
$ab.Text = $abstract
#added 8-Jun-2017
$ab = $cp.documentelement.ChildNodes | Where {$_.basename -eq
"CompanyFax"}
#set the text
[string]$abstract = $CompanyFax
$ab.Text = $abstract
#added 8-Jun-2017
$ab = $cp.documentelement.ChildNodes | Where {$_.basename -eq
"CompanyPhone"}
#set the text
[string]$abstract = $CompanyPhone
$ab.Text = $abstract
Function SaveandCloseDocumentandShutdownWord
{
#bug fix 1-Apr-2014
#reset Grammar and Spelling options back to their original settings
$Script:Word.Options.CheckGrammarAsYouType = $Script:CurrentGrammarOption
$Script:Word.Options.CheckSpellingAsYouType = $Script:CurrentSpellingOption
Function SetFileName1andFileName2
{
Param([string]$OutputFileName)
If($pwdpath.EndsWith("\"))
{
#remove the trailing \
$pwdpath = $pwdpath.SubString(0, ($pwdpath.Length - 1))
}
SetupWord
}
}
#Script begins
$script:startTime = Get-Date
If(!(Check-NeededPSSnapins "Citrix.XenApp.Commands"))
{
#We're missing Citrix Snapins that we need
$ErrorActionPreference = $SaveEAPreference
Write-Error "Missing Citrix PowerShell Snap-ins Detected, check the console
above for more information. Are you sure you are running this script on a XenApp
6.5 Server? Script will now close."
Exit
}
[bool]$Remoting = $False
$RemoteXAServer = Get-XADefaultComputerName -EA 0 4>$Null
If(![String]::IsNullOrEmpty($RemoteXAServer))
{
$Remoting = $True
}
If($Remoting)
{
Write-Verbose "$(Get-Date): Remoting is enabled to XenApp server
$RemoteXAServer"
#now need to make sure the script is not being run against a session-only
host
$Server = Get-XAServer -ServerName $RemoteXAServer -EA 0 4>$Null
If($Server.ElectionPreference -eq "WorkerMode")
{
$ErrorActionPreference = $SaveEAPreference
Write-Warning "This script cannot be run remotely against a Session-
only Host Server."
Write-Warning "Use Set-XADefaultComputerName XA65ControllerServerName
or run the script on a controller."
Write-Error "Script cannot continue. See messages above."
Exit
}
}
Else
{
Write-Verbose "$(Get-Date): Remoting is not being used"
#now need to make sure the script is not being run on a session-only host
$ServerName = (Get-Childitem env:computername).value 4>$Null
$Server = Get-XAServer -ServerName $ServerName -EA 0 4>$Null
If($Server.ElectionPreference -eq "WorkerMode")
{
$ErrorActionPreference = $SaveEAPreference
Write-Warning "This script cannot be run on a Session-only Host Server
if Remoting is not enabled."
Write-Warning "Use Set-XADefaultComputerName XA65ControllerServerName
or run the script on a controller."
Write-Error "Script cannot continue. See messages above."
Exit
}
}
ForEach($Application in $Applications)
{
Write-Verbose "$(Get-Date): `t`tProcessing application $
($Application.BrowserName)"
If(!$Summary)
{
If($Application.ApplicationType -ne "ServerDesktop" -and
$Application.ApplicationType -ne "Content")
{
#create array for appendix A
#these items are taken from
http://support.citrix.com/article/CTX159159
#Some properties that must match on both Applications
for Session Sharing to Function are:
#
#Color depth
#Screen Size
#Access Control Filters (for SmartAccess)
#Sound (unexplained in article)
#Drive Mapping (unexplained in article)
#Printer Mapping (unexplained in article)
#Encryption
If($Application.AccessSessionConditionsEnabled)
{
$tmp = @()
ForEach($filter in
$Application.AccessSessionConditions)
{
$tmp += $filter
}
$obj | Add-Member -MemberType NoteProperty
-Name AccessControlFilters -Value $tmp
}
Else
{
$obj | Add-Member -MemberType NoteProperty
-Name AccessControlFilters -Value "None"
}
$tmp = $Null
If(![String]::IsNullOrEmpty($Application.Description))
{
WriteWordLine 0 1 "Application description`t`t: "
$Application.Description
}
#type properties
WriteWordLine 0 1 "Application Type`t`t: " -nonewline
Switch ($Application.ApplicationType)
{
"Unknown" {WriteWordLine 0
0 "Unknown"}
"ServerInstalled" {WriteWordLine 0
0 "Installed application"; $TotalPublishedApps++}
"ServerDesktop" {WriteWordLine 0
0 "Server desktop"; $TotalPublishedDesktops++}
"Content" {WriteWordLine 0
0 "Content"; $TotalPublishedContent++}
"StreamedToServer" {WriteWordLine 0
0 "Streamed to server"; $TotalStreamedApps++}
"StreamedToClient" {WriteWordLine 0
0 "Streamed to client"; $TotalStreamedApps++}
"StreamedToClientOrInstalled" {WriteWordLine 0
0 "Streamed if possible, otherwise accessed from server as Installed application";
$TotalStreamedApps++}
"StreamedToClientOrStreamedToServer" {WriteWordLine 0
0 "Streamed if possible, otherwise Streamed to server"; $TotalStreamedApps++}
Default {WriteWordLine 0 0 "Application Type could
not be determined: $($Application.ApplicationType)"}
}
If(![String]::IsNullOrEmpty($Application.FolderPath))
{
WriteWordLine 0 1 "Folder path`t`t`t: "
$Application.FolderPath
}
If(![String]::IsNullOrEmpty($Application.ContentAddress))
{
WriteWordLine 0 1 "Content Address`t`t: "
$Application.ContentAddress
}
#location properties
If(!$streamedapp)
{
#requested by Pavel Stadler to put Command Line and
Working Directory in a different sized font and make it bold
If(!
[String]::IsNullOrEmpty($Application.CommandLineExecutable))
{
If($Application.CommandLineExecutable.Length
-lt 40)
{
WriteWordLine 0 1 "Command Line`t`t`t: "
-NoNewLine
WriteWordLine 0 0
$Application.CommandLineExecutable "" "Courier New" 9 $False $True
}
Else
{
WriteWordLine 0 1 "Command Line: "
WriteWordLine 0 2
$Application.CommandLineExecutable "" "Courier New" 9 $False $True
}
}
If(!
[String]::IsNullOrEmpty($Application.WorkingDirectory))
{
If($Application.WorkingDirectory.Length -lt 40)
{
WriteWordLine 0 1 "Working directory`t`t:
" -NoNewLine
WriteWordLine 0 0
$Application.WorkingDirectory "" "Courier New" 9 $False $True
}
Else
{
WriteWordLine 0 1 "Working directory: "
WriteWordLine 0 2
$Application.WorkingDirectory "" "Courier New" 9 $False $True
}
}
#servers properties
If($AppServerInfoResults)
{
If(!
[String]::IsNullOrEmpty($AppServerInfo.ServerNames))
{
WriteWordLine 0 1 "Servers:"
$TempArray = $AppServerInfo.ServerNames |
Sort
BuildTableForServerOrWG $TempArray
"Server"
$TempArray = $Null
}
If(!
[String]::IsNullOrEmpty($AppServerInfo.WorkerGroupNames))
{
WriteWordLine 0 1 "Worker Groups:"
$TempArray =
$AppServerInfo.WorkerGroupNames | Sort
BuildTableForServerOrWG $TempArray
"Server"
$TempArray = $Null
}
}
Else
{
WriteWordLine 0 2 "Unable to retrieve a list of
Servers or Worker Groups for this application"
}
}
#users properties
If($Application.AnonymousConnectionsAllowed)
{
WriteWordLine 0 1 "Allow anonymous users: "
$Application.AnonymousConnectionsAllowed
}
Else
{
If($AppServerInfoResults)
{
WriteWordLine 0 1 "Users:"
ForEach($user in $AppServerInfo.Accounts)
{
WriteWordLine 0 2 $user
}
}
Else
{
WriteWordLine 0 2 "Unable to retrieve a list of
Users for this application"
}
}
If($Application.ConnectionsThroughAccessGatewayAllowed)
{
WriteWordLine 0 0 "Yes"
}
Else
{
WriteWordLine 0 0 "No"
}
}
If($Application.OtherConnectionsAllowed)
{
WriteWordLine 0 1 "Any connection`t`t`t`t`t: "
-nonewline
If($Application.OtherConnectionsAllowed)
{
WriteWordLine 0 0 "Yes"
}
Else
{
WriteWordLine 0 0 "No"
}
}
If($Application.AccessSessionConditionsEnabled)
{
WriteWordLine 0 1 "Any connection that meets any of
the following filters: " $Application.AccessSessionConditionsEnabled
WriteWordLine 0 1 "Access Gateway Filters:"
$TableRange = $doc.Application.Selection.Range
[int]$Columns = 2
[int]$Rows =
$Application.AccessSessionConditions.count + 1
$Table = $doc.Tables.Add($TableRange, $Rows,
$Columns)
$Table.rows.first.headingformat =
$wdHeadingFormatTrue
$Table.Style = $myHash.Word_TableGrid
$Table.Borders.InsideLineStyle = $wdLineStyleSingle
$Table.Borders.OutsideLineStyle = $wdLineStyleSingle
[int]$xRow = 1
Write-Verbose "$(Get-Date): `t`t`t`tFormat first row
with column headings"
$Table.Rows.First.Shading.BackgroundPatternColor =
$wdColorGray15
$Table.Cell($xRow,1).Range.Font.Bold = $True
$Table.Cell($xRow,1).Range.Text = "Farm Name"
$Table.Cell($xRow,2).Range.Font.Bold = $True
$Table.Cell($xRow,2).Range.Text = "Filter"
ForEach($AccessCondition in
$Application.AccessSessionConditions)
{
[string]$Tmp = $AccessCondition
[string]$AGFarm = $Tmp.substring(0,
$Tmp.indexof(":"))
[string]$AGFilter =
$Tmp.substring($Tmp.indexof(":")+1)
$xRow++
Write-Verbose "$(Get-Date):
`t`t`t`t`tProcessing row for Access Condition $($Tmp)"
$Table.Cell($xRow,1).Range.Text = $AGFarm
$Table.Cell($xRow,2).Range.Text = $AGFilter
}
$Table.Rows.SetLeftIndent($Indent2TabStops,
$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
$tmp = $Null
$AGFarm = $Null
$AGFilter = $Null
}
#limits properties
WriteWordLine 0 1 "Limit instances allowed to run in server
farm`t: " -NoNewLine
If($Application.MultipleInstancesPerUserAllowed)
{
WriteWordLine 0 0 "No"
}
Else
{
WriteWordLine 0 0 "Yes"
}
If($Application.CpuPriorityLevel)
{
WriteWordLine 0 1 "Application importance`t`t`t`t: "
-nonewline
Switch ($Application.CpuPriorityLevel)
{
"Unknown" {WriteWordLine 0 0 "Unknown"}
"BelowNormal" {WriteWordLine 0 0 "Below
Normal"}
"Low" {WriteWordLine 0 0 "Low"}
"Normal" {WriteWordLine 0 0 "Normal"}
"AboveNormal" {WriteWordLine 0 0 "Above
Normal"}
"High" {WriteWordLine 0 0 "High"}
Default {WriteWordLine 0 0 "Application
importance could not be determined: $($Application.CpuPriorityLevel)"}
}
}
#appearance properties
If($Application.WindowType)
{
WriteWordLine 0 1 "Session window size`t`t`t`t: "
$Application.WindowType
}
If($Application.ColorDepth)
{
WriteWordLine 0 1 "Maximum color quality`t`t`t`t: "
-nonewline
Switch ($Application.ColorDepth)
{
"Unknown" {WriteWordLine 0 0 "Unknown color
depth"}
"Colors8Bit" {WriteWordLine 0 0 "256-color (8-
bit)"}
"Colors16Bit" {WriteWordLine 0 0 "Better Speed
(16-bit)"}
"Colors32Bit" {WriteWordLine 0 0 "Better
Appearance (32-bit)"}
Default {WriteWordLine 0 0 "Maximum color
quality could not be determined: $($Application.ColorDepth)"}
}
}
If($Application.TitleBarHidden)
{
WriteWordLine 0 1 "Hide application title bar`t`t`t:
" -nonewline
If($Application.TitleBarHidden)
{
WriteWordLine 0 0 "Enabled"
}
Else
{
WriteWordLine 0 0 "Disabled"
}
}
If($Application.MaximizedOnStartup)
{
WriteWordLine 0 1 "Maximize application at
startup`t`t`t: " -nonewline
If($Application.MaximizedOnStartup)
{
WriteWordLine 0 0 "Enabled"
}
Else
{
WriteWordLine 0 0 "Disabled"
}
}
$AppServerInfo = $Null
}
Else
{
WriteWordLine 0 0 $Application.DisplayName
}
}
}
ElseIf($Applications -eq $Null)
{
Write-Verbose "$(Get-Date): There are no Applications published"
}
Else
{
Write-Warning "Application information could not be retrieved."
}
$Applications = $Null
Write-Verbose "$(Get-Date): Finished Processing Applications"
Write-Verbose "$(Get-Date): "
}
If($ConfigLog)
{
Write-Verbose "$(Get-Date): Processing Configuration Logging/History
Report"
#history AKA Configuration Logging report
#only process if $ConfigLog = $True and XA65ConfigLog.udl file exists
#build connection string
#User ID is account that has access permission for the configuration
logging database
#Initial Catalog is the name of the Configuration Logging SQL Database
#bug fixed by Esther Barthel
If(Test-Path "$($pwd.path)\XA65ConfigLog.udl")
{
Write-Verbose "$(Get-Date): `tRetrieving logging data for date
range $($StartDate) through $($EndDate)"
$ConnectionString = Get-Content "$($pwd.path)\XA65ConfigLog.udl"
4>$Null| select-object -last 1
$ConfigLogReport = Get-CtxConfigurationLogReport
-connectionstring $ConnectionString -TimePeriodFrom $StartDate -TimePeriodTo
$EndDate -EA 0 4>$Null
$Table.Cell($xRow,1).Shading.BackgroundPatternColor = $wdColorGray05
$Table.Cell($xRow,2).Shading.BackgroundPatternColor = $wdColorGray05
$Table.Cell($xRow,3).Shading.BackgroundPatternColor = $wdColorGray05
$Table.Cell($xRow,4).Shading.BackgroundPatternColor = $wdColorGray05
$Table.Cell($xRow,5).Shading.BackgroundPatternColor = $wdColorGray05
$Table.Cell($xRow,6).Shading.BackgroundPatternColor = $wdColorGray05
}
$Table.Cell($xRow,1).Range.Font.size = 9
$Table.Cell($xRow,1).Range.Text = $Item.Date
$Table.Cell($xRow,2).Range.Font.size = 9
$Table.Cell($xRow,2).Range.Text = $Item.Account
$Table.Cell($xRow,3).Range.Font.size = 9
$Table.Cell($xRow,3).Range.Text = $Item.Description
$Table.Cell($xRow,4).Range.Font.size = 9
$Table.Cell($xRow,4).Range.Text = $Item.TaskType
$Table.Cell($xRow,5).Range.Font.size = 9
$Table.Cell($xRow,5).Range.Text = $Item.ItemType
$Table.Cell($xRow,6).Range.Font.size = 9
$Table.Cell($xRow,6).Range.Text = $Item.ItemName
}
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
}
ElseIf($? -and $ConfigLogReport -eq $Null)
{
Write-Verbose "$(Get-Date): There was no configuration
logging data returned"
WriteWordLine 0 0 "There was no configuration logging data
returned"
}
ElseIf(!$?)
{
Write-Warning "Error retrieving configuration logging data"
WriteWordLine 0 0 "Error retrieving configuration logging
data"
}
}
Else
{
Write-Warning "Configuration Logging is enabled but the
XA65ConfigLog.udl file was not found"
}
$ConnectionString = $Null
$ConfigLogReport = $Null
}
If($LoadBalancingPolicyFilter.AllowConnectionsThroughAccessGateway)
{
WriteWordLine 0 0 "Yes"
}
Else
{
WriteWordLine 0 0 "No"
}
If($LoadBalancingPolicyFilter.AllowConnectionsThroughAccessGateway)
{
If($LoadBalancingPolicyFilter.AllowOtherConnections)
{
WriteWordLine 0 2 "Any connection"
}
Else
{
WriteWordLine 0 2 "Any connection that
meets any of the following filters"
If($LoadBalancingPolicyFilter.AccessSessionConditions)
{
Write-Verbose "$(Get-Date):
`t`t`tCreate table for Load Balancing Policy Access Session Condition"
$TableRange =
$doc.Application.Selection.Range
[int]$Columns = 2
[int]$Rows =
$LoadBalancingPolicyFilter.AccessSessionConditions.count + 1
$Table =
$doc.Tables.Add($TableRange, $Rows, $Columns)
$Table.rows.first.headingformat =
$wdHeadingFormatTrue
$Table.Style =
$myHash.Word_TableGrid
$Table.Borders.InsideLineStyle =
$wdLineStyleSingle
$Table.Borders.OutsideLineStyle =
$wdLineStyleSingle
[int]$xRow = 1
Write-Verbose "$(Get-Date):
`t`t`t`tFormat first row with column headings"
$Table.Rows.First.Shading.BackgroundPatternColor = $wdColorGray15
$Table.Cell($xRow,1).Range.Font.Bold = $True
$Table.Cell($xRow,1).Range.Text =
"Farm Name"
$Table.Cell($xRow,2).Range.Font.Bold = $True
$Table.Cell($xRow,2).Range.Text =
"Filter"
ForEach($AccessSessionCondition in
$LoadBalancingPolicyFilter.AccessSessionConditions)
{
[string]$Tmp =
$AccessSessionCondition
[string]$AGFarm =
$Tmp.substring(0, $Tmp.indexof(":"))
[string]$AGFilter =
$Tmp.substring($Tmp.indexof(":")+1)
$xRow++
Write-Verbose "$(Get-Date):
`t`t`t`t`tProcessing row for Access Session Condition $($Tmp)"
$Table.Cell($xRow,1).Range.Text = $AGFarm
$Table.Cell($xRow,2).Range.Text = $AGFilter
}
$Table.Rows.SetLeftIndent($Indent2TabStops,$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
$tmp = $Null
$AGFarm = $Null
$AGFilter = $Null
}
}
}
}
If($LoadBalancingPolicyFilter.ClientIPAddressEnabled)
{
WriteWordLine 0 1 "Filter based on client IP address"
If($LoadBalancingPolicyFilter.ApplyToAllClientIPAddresses)
{
WriteWordLine 0 2 "Apply to all client IP
addresses"
}
Else
{
If($LoadBalancingPolicyFilter.AllowedIPAddresses)
{
ForEach($AllowedIPAddress in
$LoadBalancingPolicyFilter.AllowedIPAddresses)
{
WriteWordLine 0 2 "Client IP
Address Matched: " $AllowedIPAddress
}
}
If($LoadBalancingPolicyFilter.DeniedIPAddresses)
{
ForEach($DeniedIPAddress in
$LoadBalancingPolicyFilter.DeniedIPAddresses)
{
WriteWordLine 0 2 "Client IP
Address Ignored: " $DeniedIPAddress
}
}
}
}
If($LoadBalancingPolicyFilter.ClientNameEnabled)
{
WriteWordLine 0 1 "Filter based on client name"
If($LoadBalancingPolicyFilter.ApplyToAllClientNames)
{
WriteWordLine 0 2 "Apply to all client names"
}
Else
{
If($LoadBalancingPolicyFilter.AllowedClientNames)
{
ForEach($AllowedClientName in
$LoadBalancingPolicyFilter.AllowedClientNames)
{
WriteWordLine 0 2 "Client Name
Matched: " $AllowedClientName
}
}
If($LoadBalancingPolicyFilter.DeniedClientNames)
{
ForEach($DeniedClientName in
$LoadBalancingPolicyFilter.DeniedClientNames)
{
WriteWordLine 0 2 "Client Name
Ignored: " $DeniedClientName
}
}
}
}
If($LoadBalancingPolicyFilter.AccountEnabled)
{
WriteWordLine 0 1 "Filter based on user"
WriteWordLine 0 2 "Apply to anonymous users: "
-nonewline
If($LoadBalancingPolicyFilter.ApplyToAnonymousAccounts)
{
WriteWordLine 0 0 "Yes"
}
Else
{
WriteWordLine 0 0 "No"
}
If($LoadBalancingPolicyFilter.ApplyToAllExplicitAccounts)
{
WriteWordLine 0 2 "Apply to all explicit (non-
anonymous) users"
}
Else
{
If($LoadBalancingPolicyFilter.AllowedAccounts)
{
ForEach($AllowedAccount in
$LoadBalancingPolicyFilter.AllowedAccounts)
{
WriteWordLine 0 2 "User Matched: "
$AllowedAccount
}
}
If($LoadBalancingPolicyFilter.DeniedAccounts)
{
ForEach($DeniedAccount in
$LoadBalancingPolicyFilter.DeniedAccounts)
{
WriteWordLine 0 2 "User Ignored: "
$DeniedAccount
}
}
}
}
If($LoadBalancingPolicyConfiguration.WorkerGroupPreferenceAndFailoverState)
{
WriteWordLine 0 1 "Configure application connection
preference based on worker group"
If($LoadBalancingPolicyConfiguration.WorkerGroupPreferences)
{
Write-Verbose "$(Get-Date): `t`t`tCreate table
for Load Balancing Policy Worker Group Filter"
$TableRange = $doc.Application.Selection.Range
[int]$Columns = 2
[int]$Rows =
$LoadBalancingPolicyConfiguration.WorkerGroupPreferences.count + 1
$Table = $doc.Tables.Add($TableRange, $Rows,
$Columns)
$Table.rows.first.headingformat =
$wdHeadingFormatTrue
$Table.Style = $myHash.Word_TableGrid
$Table.Borders.InsideLineStyle =
$wdLineStyleSingle
$Table.Borders.OutsideLineStyle =
$wdLineStyleSingle
[int]$xRow = 1
Write-Verbose "$(Get-Date): `t`t`t`tFormat
first row with column headings"
$Table.Rows.First.Shading.BackgroundPatternColor = $wdColorGray15
$Table.Cell($xRow,1).Range.Font.Bold = $True
$Table.Cell($xRow,1).Range.Text = "Worker
Group"
$Table.Cell($xRow,2).Range.Font.Bold = $True
$Table.Cell($xRow,2).Range.Text = "Priority"
ForEach($WorkerGroupPreference in
$LoadBalancingPolicyConfiguration.WorkerGroupPreferences)
{
[string]$Tmp = $WorkerGroupPreference
[string]$WGName =
$Tmp.substring($Tmp.indexof("=")+1)
[string]$WGPriority =
$Tmp.substring($Tmp.indexof(":")+1, (($Tmp.indexof("=")-1)-$Tmp.indexof(":")))
$xRow++
Write-Verbose "$(Get-Date):
`t`t`tProcessing row for Worker Group Filter $($Tmp)"
$Table.Cell($xRow,1).Range.Text = $WGName
$Table.Cell($xRow,2).Range.Text =
$WGPriority
}
$Table.Rows.SetLeftIndent($Indent2TabStops,
$wdAdjustProportional)
$Table.AutoFitBehavior($wdAutoFitContent)
FindWordDocumentEnd
$tmp = $Null
$WGName = $Null
$WGPriority = $Null
}
}
If($LoadBalancingPolicyConfiguration.StreamingDeliveryProtocolState -eq
"Enabled")
{
WriteWordLine 0 1 "Set the delivery protocols for
applications streamed to client"
WriteWordLine 0 2 "" -nonewline
Switch
($LoadBalancingPolicyConfiguration.StreamingDeliveryOption)
{
"Unknown" {WriteWordLine 0 0
"Unknown"}
"ForceServerAccess" {WriteWordLine 0 0 "Do
not allow applications to stream to the client"}
"ForcedStreamedDelivery" {WriteWordLine 0 0
"Force applications to stream to the client"}
Default {WriteWordLine 0 0 "Delivery protocol
could not be determined: $
($LoadBalancingPolicyConfiguration.StreamingDeliveryOption)"}
}
}
Elseif($LoadBalancingPolicyConfiguration.StreamingDeliveryProtocolState -eq
"Disabled")
{
#In the GUI, if "Set the delivery protocols for
applications streamed to client" IS selected AND
#"Allow applications to stream to the client or run
on a Terminal Server (Default)" IS selected
#then "Set the delivery protocols for applications
streamed to client" is set to Disabled
WriteWordLine 0 1 "Set the delivery protocols for
applications streamed to client"
WriteWordLine 0 2 "Allow applications to stream to
the client or run on a Terminal Server (Default)"
}
Else
{
WriteWordLine 0 1 "Streamed App Delivery is not
configured"
}
$LoadBalancingPolicyConfiguration = $Null
$LoadBalancingPolicyFilter = $Null
}
Else
{
WriteWordLine 0 0 $LoadBalancingPolicy.PolicyName
}
}
}
Elseif($LoadBalancingPolicies -eq $Null)
{
Write-Verbose "$(Get-Date): There are no Load balancing policies
created"
}
Else
{
Write-Warning "Load balancing policy information could not be
retrieved"
}
$LoadBalancingPolicies = $Null
Write-Verbose "$(Get-Date): Finished Processing Load Balancing Policies"
Write-Verbose "$(Get-Date): "
}
If($LoadEvaluator.IsBuiltIn)
{
WriteWordLine 0 1 "Built-in Load Evaluator"
}
Else
{
WriteWordLine 0 1 "User created load evaluator"
}
If($LoadEvaluator.ApplicationUserLoadEnabled)
{
WriteWordLine 0 1 "Application User Load Settings"
WriteWordLine 0 2 "Report full load when the # of
users for this application equals: " $LoadEvaluator.ApplicationUserLoad
WriteWordLine 0 2 "Application: "
$LoadEvaluator.ApplicationBrowserName
}
If($LoadEvaluator.ContextSwitchesEnabled)
{
WriteWordLine 0 1 "Context Switches Settings"
WriteWordLine 0 2 "Report full load when the # of
context Switches per second is > than: " $LoadEvaluator.ContextSwitches[1]
WriteWordLine 0 2 "Report no load when the # of
context Switches per second is <= to: " $LoadEvaluator.ContextSwitches[0]
}
If($LoadEvaluator.CpuUtilizationEnabled)
{
WriteWordLine 0 1 "CPU Utilization Settings"
WriteWordLine 0 2 "Report full load when the
processor utilization % is > than: " $LoadEvaluator.CpuUtilization[1]
WriteWordLine 0 2 "Report no load when the processor
utilization % is <= to: " $LoadEvaluator.CpuUtilization[0]
}
If($LoadEvaluator.DiskDataIOEnabled)
{
WriteWordLine 0 1 "Disk Data I/O Settings"
WriteWordLine 0 2 "Report full load when the total
disk I/O in kbps is > than: " $LoadEvaluator.DiskDataIO[1]
WriteWordLine 0 2 "Report no load when the total disk
I/O in kbps per second is <= to: " $LoadEvaluator.DiskDataIO[0]
}
If($LoadEvaluator.DiskOperationsEnabled)
{
WriteWordLine 0 1 "Disk Operations Settings"
WriteWordLine 0 2 "Report full load when the total #
of R/W operations per second is > than: " $LoadEvaluator.DiskOperations[1]
WriteWordLine 0 2 "Report no load when the total # of
R/W operations per second is <= to: " $LoadEvaluator.DiskOperations[0]
}
If($LoadEvaluator.IPRangesEnabled)
{
WriteWordLine 0 1 "IP Range Settings"
If($LoadEvaluator.IPRangesAllowed)
{
WriteWordLine 0 2 "Allow " -NoNewLine
}
Else
{
WriteWordLine 0 2 "Deny " -NoNewLine
}
WriteWordLine 0 0 "client connections from the listed
IP Ranges"
ForEach($IPRange in $LoadEvaluator.IPRanges)
{
WriteWordLine 0 3 "IP Address Ranges: "
$IPRange
}
}
If($LoadEvaluator.LoadThrottlingEnabled)
{
WriteWordLine 0 1 "Load Throttling Settings"
WriteWordLine 0 2 "Impact of logons on load: "
-nonewline
Switch ($LoadEvaluator.LoadThrottling)
{
"Unknown" {WriteWordLine 0 0 "Unknown"}
"Extreme" {WriteWordLine 0 0 "Extreme"}
"High" {WriteWordLine 0 0 "High
(Default)"}
"MediumHigh" {WriteWordLine 0 0 "Medium High"}
"Medium" {WriteWordLine 0 0 "Medium"}
"MediumLow" {WriteWordLine 0 0 "Medium Low"}
Default {WriteWordLine 0 0 "Impact of logons on
load could not be determined: $($LoadEvaluator.LoadThrottling)"}
}
}
If($LoadEvaluator.MemoryUsageEnabled)
{
WriteWordLine 0 1 "Memory Usage Settings"
WriteWordLine 0 2 "Report full load when the memory
usage is > than: " $LoadEvaluator.MemoryUsage[1]
WriteWordLine 0 2 "Report no load when the memory
usage is <= to: " $LoadEvaluator.MemoryUsage[0]
}
If($LoadEvaluator.PageFaultsEnabled)
{
WriteWordLine 0 1 "Page Faults Settings"
WriteWordLine 0 2 "Report full load when the # of
page faults per second is > than: " $LoadEvaluator.PageFaults[1]
WriteWordLine 0 2 "Report no load when the # of page
faults per second is <= to: " $LoadEvaluator.PageFaults[0]
}
If($LoadEvaluator.PageSwapsEnabled)
{
WriteWordLine 0 1 "Page Swaps Settings"
WriteWordLine 0 2 "Report full load when the # of
page swaps per second is > than: " $LoadEvaluator.PageSwaps[1]
WriteWordLine 0 2 "Report no load when the # of page
swaps per second is <= to: " $LoadEvaluator.PageSwaps[0]
}
If($LoadEvaluator.ScheduleEnabled)
{
WriteWordLine 0 1 "Scheduling Settings"
WriteWordLine 0 2 "Sunday Schedule`t: "
$LoadEvaluator.SundaySchedule
WriteWordLine 0 2 "Monday Schedule`t: "
$LoadEvaluator.MondaySchedule
WriteWordLine 0 2 "Tuesday Schedule`t: "
$LoadEvaluator.TuesdaySchedule
WriteWordLine 0 2 "Wednesday Schedule`t: "
$LoadEvaluator.WednesdaySchedule
WriteWordLine 0 2 "Thursday Schedule`t: "
$LoadEvaluator.ThursdaySchedule
WriteWordLine 0 2 "Friday Schedule`t`t: "
$LoadEvaluator.FridaySchedule
WriteWordLine 0 2 "Saturday Schedule`t: "
$LoadEvaluator.SaturdaySchedule
}
If($LoadEvaluator.ServerUserLoadEnabled)
{
WriteWordLine 0 1 "Server User Load Settings"
WriteWordLine 0 2 "Report full load when the # of
server users equals: " $LoadEvaluator.ServerUserLoad
}
WriteWordLine 0 0 ""
}
Else
{
WriteWordLine 0 0 $LoadEvaluator.LoadEvaluatorName
}
}
}
ElseIf(!$?)
{
Write-Warning "Load Evaluator information could not be retrieved"
}
Else
{
Write-Warning "No results returned for Load Evaluator information"
}
$LoadEvaluators = $Null
Write-Verbose "$(Get-Date): Finished Processing Load Evaluators"
Write-Verbose "$(Get-Date): "
}
If(!$Summary)
{
[bool]$SvrOnline = $False
Write-Verbose "$(Get-Date): `t`t`tTesting to see if $
($server.ServerName) is online and reachable"
If(Test-Connection -ComputerName $server.servername -quiet
-EA 0)
{
$SvrOnline = $True
If($Hardware -and $Software)
{
Write-Verbose "$(Get-Date): `t`t`t`t$
($server.ServerName) is online."
Write-Verbose "$(Get-Date): `t`t`t`tHardware
and Software Inventory, Citrix Services and Hotfix areas will be processed."
}
ElseIf($Hardware -and !($Software))
{
Write-Verbose "$(Get-Date): `t`t`t`t$
($server.ServerName) is online."
Write-Verbose "$(Get-Date): `t`t`t`tHardware
inventory, Citrix Services and Hotfix areas will be processed."
}
ElseIf(!($Hardware) -and $Software)
{
Write-Verbose "$(Get-Date): `t`t`t`t$
($server.ServerName) is online."
Write-Verbose "$(Get-Date): `t`t`t`tSoftware
Inventory, Citrix Services and Hotfix areas will be processed."
}
Else
{
Write-Verbose "$(Get-Date): `t`t`t`t$
($server.ServerName) is online."
Write-Verbose "$(Get-Date): `t`t`t`tCitrix
Services and Hotfix areas will be processed."
}
}
If($SvrOnline)
{
$Reg =
[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',
$server.ServerName)
Try
{
$RegKey=
$Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Citrix\\Wfshell\\TWI")
$SSDisabled = $RegKey.GetValue("SeamlessFlags")
If($SSDisabled -eq 1)
{
$obj | Add-Member -MemberType
NoteProperty -Name SessionSharing -Value "Disabled"
}
Else
{
$obj | Add-Member -MemberType
NoteProperty -Name SessionSharing -Value "Enabled"
}
}
Catch
{
$obj | Add-Member -MemberType
NoteProperty -Name SessionSharing -Value "Not Available"
}
}
Else
{
$obj | Add-Member -MemberType NoteProperty -Name
SessionSharing -Value "Server Offline"
}
$ServerItems += $obj
WriteWordLine 2 0 $server.ServerName
WriteWordLine 0 1 "Product`t`t`t`t: "
$server.CitrixProductName
WriteWordLine 0 1 "Edition`t`t`t`t: " $server.CitrixEdition
WriteWordLine 0 1 "Version`t`t`t`t: " $server.CitrixVersion
WriteWordLine 0 1 "Service Pack`t`t`t: "
$server.CitrixServicePack
WriteWordLine 0 1 "IP Address`t`t`t: " $server.IPAddresses
WriteWordLine 0 1 "Logons`t`t`t`t: " -NoNewLine
If($server.LogOnsEnabled)
{
WriteWordLine 0 0 "Enabled"
}
Else
{
WriteWordLine 0 0 "Disabled"
}
WriteWordLine 0 1 "Logon Control Mode`t`t: " -nonewline
Switch ($Server.LogOnMode)
{
"Unknown" {WriteWordLine 0 0
"Unknown"}
"AllowLogOns" {WriteWordLine 0 0
"Allow logons and reconnections"}
"ProhibitNewLogOnsUntilRestart" {WriteWordLine 0 0
"Prohibit logons until server restart"}
"ProhibitNewLogOns " {WriteWordLine 0 0
"Prohibit logons only"}
"ProhibitLogOns " {WriteWordLine 0 0
"Prohibit logons and reconnections"}
Default {WriteWordLine 0 0 "Logon control mode could
not be determined: $($Server.LogOnMode)"}
}
FindWordDocumentEnd
WriteWordLine 0 0 ""
}
$UninstallKey1="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',
$Server.ServerName)
#Drill down into the Uninstall key using the
OpenSubKey Method
$regkey1=$reg.OpenSubKey($UninstallKey1)
$UninstallKey2="SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal
l"
$regkey2=$reg.OpenSubKey($UninstallKey2)
If($regkey2 -ne $Null)
{
$subkeys2=$regkey2.GetSubKeyNames()
ForEach($key in $subkeys2)
{
$thisKey=$UninstallKey2+"\\"+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
if(![String]::IsNullOrEmpty($
($thisSubKey.GetValue("DisplayName"))))
{
$obj = New-Object PSObject
$obj | Add-Member -MemberType
NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
$obj | Add-Member -MemberType
NoteProperty -Name "DisplayVersion" -Value $
($thisSubKey.GetValue("DisplayVersion"))
$InstalledApps += $obj
}
}
}
FindWordDocumentEnd
WriteWordLine 0 0 ""
}
Try
{
#Iain Brighton optimization 5-Jun-2014
#Replaced with a single call to retrieve
services via WMI. The repeated
## "Get-WMIObject Win32_Service -Filter" calls
were the major delays in the script.
## If we need to retrieve the StartUp type
might as well just use WMI.
$Services = Get-WMIObject Win32_Service
-ComputerName $server.ServerName -EA 0 | Where {$_.DisplayName -like "*Citrix*"} |
Sort DisplayName
}
Catch
{
$Services = $Null
}
ForEach($Service in $Services)
{
#Write-Verbose "$(Get-Date): `t`t`t
Processing service $($Service.DisplayName)";
$Table.Rows.SetLeftIndent($Indent1TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
}
}
ElseIf(!$?)
{
Write-Warning "No services were retrieved."
If($MSWord -or $PDF)
{
WriteWordLine 0 0 "Warning: No Services
were retrieved" "" $Null 0 $False $True
WriteWordLine 0 1 "If this is a trusted
Forest, you may need to rerun the" "" $Null 0 $False $True
WriteWordLine 0 1 "script with Admin
credentials from the trusted Forest." "" $Null 0 $False $True
}
}
Else
{
Write-Warning "Services retrieval was
successful but no services were returned."
WriteWordLine 0 0 "Services retrieval was
successful but no services were returned." "" $Null 0 $False $True
}
Catch
{
$hotfixes = $Null
}
ForEach($hotfix in $hotfixes)
{
$HotfixArray += $hotfix.HotfixName
Switch ($hotfix.HotfixName)
{
"XA650W2K8R2X64R02" {$HRP2Installed
= $True}
"XA650W2K8R2X64R03" {$HRP3Installed
= $True}
"XA650W2K8R2X64R04" {$HRP4Installed
= $True}
"XA650W2K8R2X64R05" {$HRP5Installed
= $True}
"XA650W2K8R2X64R06" {$HRP6Installed
= $True}
"XA650W2K8R2X64R07" {$HRP7Installed
= $True}
}
$InstallDate =
$hotfix.InstalledOn.ToString()
$CurrentServiceIndex++;
}
}
$Table.Rows.SetLeftIndent($Indent1TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 0 ""
}
If($RecommendedList.count -gt 0)
{
Write-Verbose "$(Get-Date): `t`tCreate
Word Table for Citrix Hotfixes"
If($MSWord -or $PDF)
{
WriteWordLine 0 1 "Citrix
Recommended Hotfixes:"
## Create an array of hashtables to
store our hotfixes
[System.Collections.Hashtable[]]
$HotfixesWordTable = @();
## Create an array of hashtables to
store references of cells that we wish to highlight after the table has been added
[System.Collections.Hashtable[]]
$HighlightedCells = @();
## Seed the row index from the
second row
[int] $CurrentServiceIndex = 2;
}
ForEach($element in $RecommendedList)
{
$Tmp = $Null
If(!($HotfixArray -contains
$element))
{
#missing a recommended Citrix
hotfix
$Tmp = "Not Installed"
}
Else
{
$Tmp = "Installed"
}
If($MSWord -or $PDF)
{
## Add the required
key/values to the hashtable
$WordTableRowHash =
@{ CitrixHotfix = $element; Status = $Tmp}
$Table.Rows.SetLeftIndent($Indent1TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 0 ""
}
}
#build list of installed Microsoft hotfixes
Write-Verbose "$(Get-Date): `t`tProcessing
Microsoft hotfixes for server $($server.ServerName)"
[bool]$GotMSHotfixes = $True
Try
{
$results = Get-HotFix -computername
$Server.ServerName
$MSInstalledHotfixes = $results | select-
object -Expand HotFixID | Sort HotFixID
$results = $Null
}
Catch
{
$GotMSHotfixes = $False
}
If($GotMSHotfixes)
{
If($server.OSServicePack.IndexOf('1') -gt
0)
{
#Server 2008 R2 SP1 installed
$RecommendedList = @("KB2620656",
"KB2647753", "KB2728738", "KB2748302",
"KB2775511",
"KB2778831", "KB2871131", "KB2896256",
"KB2908190",
"KB2920289", "KB917607")
}
Else
{
#Server 2008 R2 without SP1
installed
$RecommendedList = @("KB2265716",
"KB2383928", "KB2647753", "KB2728738",
"KB2748302",
"KB2775511", "KB2778831", "KB2871131",
"KB2896256",
"KB3014783", "KB917607", "KB975777",
"KB979530",
"KB980663", "KB983460")
}
If($RecommendedList.count -gt 0)
{
Write-Verbose "$(Get-Date):
`t`tCreate Word Table for Microsoft Hotfixes"
Write-Verbose "$(Get-Date): `t`tAdd
Microsoft hotfix table to doc"
If($MSWord -or $PDF)
{
WriteWordLine 0 1 "Microsoft
Recommended Hotfixes (from CTX129229):"
## Create an array of
hashtables to store our hotfixes
ForEach($hotfix in
$RecommendedList)
{
$Tmp = $Null
If(!($MSInstalledHotfixes
-contains $hotfix))
{
$Tmp = "Not Installed"
}
Else
{
$Tmp = "Installed"
}
If($MSWord -or $PDF)
{
## Add the required
key/values to the hashtable
$WordTableRowHash =
@{ MicrosoftHotfix = $hotfix; Status = $Tmp}
$Table.Rows.SetLeftIndent($Indent1TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
WriteWordLine 0 1 "Not all
missing Microsoft hotfixes may be needed for this server `n`tor might already be
replaced and not recorded in CTX129229."
WriteWordLine 0 0 ""
}
}
}
Else
{
Write-Verbose "$(Get-Date): Get-HotFix
failed for $($server.ServerName)"
Write-Warning "Get-HotFix failed for $
($server.ServerName)"
If($MSWord -or $PDF)
{
WriteWordLine 0 0 "Get-HotFix
failed for $($server.ServerName)" "" $Null 0 $False $True
WriteWordLine 0 0 "On $
($server.ServerName) you may need to run winmgmt /verifyrepository and winmgmt
/salvagerepository"
}
}
}
ElseIf(!$?)
{
Write-Warning "No Citrix hotfixes were
retrieved"
If($MSWORD -or $PDF)
{
WriteWordLine 0 0 "Warning: No Citrix
hotfixes were retrieved" "" $Null 0 $False $True
}
}
Else
{
Write-Warning "Citrix hotfix retrieval was
successful but no Citrix hotfixes were returned."
If($MSWORD -or $PDF)
{
WriteWordLine 0 0 "Citrix hotfix
retrieval was successful but no Citrix hotfixes were returned." "" $Null 0 $False
$True
}
}
}
Else
{
Write-Verbose "$(Get-Date): `t`t$($server.ServerName)
is offline or unreachable. Citrix Services and Hotfix areas skipped."
WriteWordLine 0 0 "Server $($server.ServerName) was
offline or unreachable at "(Get-date).ToString()
WriteWordLine 0 0 "The Citrix Services and Hotfix
areas were skipped."
}
WriteWordLine 0 0 ""
Write-Verbose "$(Get-Date): `tFinished Processing server $
($server.ServerName)"
Write-Verbose "$(Get-Date): "
}
Else
{
WriteWordLine 0 0 $server.ServerName
$TotalServers++
}
}
}
ElseIf(!$?)
{
Write-Warning "Server information could not be retrieved"
}
Else
{
Write-Warning "No results returned for Server information"
}
$servers = $Null
Write-Verbose "$(Get-Date): Finished Processing Servers"
Write-Verbose "$(Get-Date): "
}
FindWordDocumentEnd
}
WriteWordLine 0 0 ""
}
Else
{
WriteWordLine 0 0 $WorkerGroup.WorkerGroupName
$TotalWGs++
}
}
}
ElseIf($WorkerGroups -eq $Null)
{
Write-Verbose "$(Get-Date): There are no Worker Groups created"
}
Else
{
Write-Warning "No results returned for Worker Group information"
}
$WorkerGroups = $Null
Write-Verbose "$(Get-Date): Finished Processing Worker Groups"
Write-Verbose "$(Get-Date): "
}
ForEach($Server in $Servers)
{
WriteWordLine 0 2 "Server Name and Preference:
" $server.ServerName -NoNewLine
WriteWordLine 0 0 " - " -nonewline
Switch ($server.ElectionPreference)
{
"Unknown" {WriteWordLine 0 0
"Unknown"}
"MostPreferred" {WriteWordLine 0 0
"Most Preferred"}
"Preferred" {WriteWordLine 0 0
"Preferred"}
"DefaultPreference" {WriteWordLine 0 0
"Default Preference"}
"NotPreferred" {WriteWordLine 0 0
"Not Preferred"}
"WorkerMode" {WriteWordLine 0 0
"Worker Mode"}
Default {WriteWordLine 0 0 "Zone
preference could not be determined: $($server.ElectionPreference)"}
}
}
}
Else
{
WriteWordLine 0 1 "Unable to enumerate servers in the
zone"
}
$Servers = $Null
}
Else
{
WriteWordLine 0 0 $Zone.ZoneName
}
}
}
ElseIf(!$?)
{
Write-Warning "Zone information could not be retrieved"
}
Else
{
Write-Warning "No results returned for Zone information"
}
$Servers = $Null
$Zones = $Null
Write-Verbose "$(Get-Date): Finished Processing Zones"
Write-Verbose "$(Get-Date): "
}
If(!$Summary)
{
If($Global:TotalADPoliciesNotProcessed -gt 0)
{
Write-Verbose "$(Get-Date): Processing list of
Citrix AD Policies not processed"
$ADPoliciesNotProcessed =
$ADPoliciesNotProcessed | Sort -unique
WriteWordLine 0 0 ""
WriteWordLine 2 0 "Active Directory Citrix
policies that could not be processed:"
ForEach($Policy in $ADPoliciesNotProcessed)
{
Write-Verbose "$(Get-Date): `t Processing
skipped Citrix AD policy $($Policy)"
WriteWordLine 0 1 $Policy
}
Write-Verbose "$(Get-Date): Finished processing
list of Citrix AD Policies not processed"
WriteWordLine 0 0 ""
}
}
Write-Verbose "$(Get-Date): Finished Processing Citrix AD
Policies"
Write-Verbose "$(Get-Date): "
}
Else
{
Write-Verbose "$(Get-Date): There are no Citrix AD based
policies to process"
Write-Verbose "$(Get-Date): "
}
Write-Verbose "$(Get-Date): Finished Processing Citrix Policies"
Write-Verbose "$(Get-Date): "
}
}
}
ForEach($Item in $SessionSharingItems)
{
If($MSWord -or $PDF)
{
## Add the required key/values to the hashtable
$WordTableRowHash = @{ ApplicationName = $Item.ApplicationName;
MaximumColorQuality = $Item.MaximumColorQuality;
SessionWindowSize = $Item.SessionWindowSize;
AccessControlFilters = $Item.AccessControlFilters;
Encryption = $Item.Encryption}
$CurrentServiceIndex++;
}
}
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$TableRange = $Null
$Table = $Null
}
$CurrentServiceIndex++;
}
}
$Table.Rows.SetLeftIndent($Indent0TabStops,$wdAdjustProportional)
FindWordDocumentEnd
$Table = $Null
}
$GotFile = $False
If($PDF)
{
If(Test-Path "$($Script:FileName2)")
{
Write-Verbose "$(Get-Date): $($Script:FileName2) is ready for use"
$GotFile = $True
}
Else
{
Write-Warning "$(Get-Date): Unable to save the output file, $
($Script:FileName2)"
Write-Error "Unable to save the output file, $($Script:FileName2)"
}
}
Else
{
If(Test-Path "$($Script:FileName1)")
{
Write-Verbose "$(Get-Date): $($Script:FileName1) is ready for use"
$GotFile = $True
}
Else
{
Write-Warning "$(Get-Date): Unable to save the output file, $
($Script:FileName1)"
Write-Error "Unable to save the output file, $($Script:FileName1)"
}
}
#http://poshtips.com/measuring-elapsed-time-in-powershell/
Write-Verbose "$(Get-Date): Script started: $($Script:StartTime)"
Write-Verbose "$(Get-Date): Script ended: $(Get-Date)"
$runtime = $(Get-Date) - $Script:StartTime
$Str = [string]::format("{0} days, {1} hours, {2} minutes, {3}.{4} seconds", `
$runtime.Days, `
$runtime.Hours, `
$runtime.Minutes, `
$runtime.Seconds,
$runtime.Milliseconds)
Write-Verbose "$(Get-Date): Elapsed time: $($Str)"
$runtime = $Null
$Str = $Null
$ErrorActionPreference = $SaveEAPreference