Printer redirection cannot be applied to client computers that connect to a Windows Server 2008 R2 SP1-based Terminal Services server
http://go.microsoft.com/fwlink/?linkid=506844
Target | Microsoft.KnowledgeServices.Windows.OperatingSystem | ||
Parent Monitor | System.Health.ConfigurationState | ||
Category | Alert | ||
Enabled | True | ||
Alert Generate | True | ||
Alert Severity | Error | ||
Alert Priority | Normal | ||
Alert Auto Resolve | True | ||
Monitor Type | Microsoft.KnowledgeServices.Library.PowerShellMonitorEx | ||
Remotable | True | ||
Accessibility | Public | ||
Alert Message |
| ||
RunAs | Default | ||
Comment | SupportTopic=TBD;VersionNumber=1.0.0.0; |
<UnitMonitor ID="Monitor_AKN689148" Comment="SupportTopic=TBD;VersionNumber=1.0.0.0;" Accessibility="Public" Enabled="true" Target="MicrosoftKnowledgeServicesWindowsLibrary!Microsoft.KnowledgeServices.Windows.OperatingSystem" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.PowerShellMonitorEx" ConfirmDelivery="true">
<Category>Alert</Category>
<AlertSettings AlertMessage="MonitorMessagec84585340b1b4a7aa4f81e19bbd3a403">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AKN689148.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>StrOSVersion</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.OperatingSystem"]/OSVersion$</Value>
</Parameter>
</Parameters>
<ScriptBody>
param($StrOSVersion)
$ErrorActionPreference = "Stop"
# Set up the arguments
$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "StrOSVersion" $StrOSVersion
# Set up the output
$global:scriptoutput = new-object psobject
$scriptoutput | add-member NoteProperty "HasIssue" $false
# Environment
$scriptenv = New-Object psobject
$scriptenv | Add-Member NoteProperty "RuntimeError" $false
$scriptenv | Add-Member NoteProperty "IsFileVersionLowerThanRequired" $false
$scriptenv | Add-Member NoteProperty "IsEasyPrintPrinterRedirectionEnabled" $false
$scriptenv | Add-Member NoteProperty "IsTerminalServicesRoleEnabled" $false
$scriptenv | Add-Member ScriptProperty "IsWindowsServer2008R2Sp1Env" {([version]$scriptargs.StrOSVersion).Major -eq 6 -and ([version]$scriptargs.StrOSVersion).Minor -eq 1 -and ([version]$scriptargs.StrOSVersion).Build -eq 7601}
# Terminal services role is enabled
function Check-IsTerminalServicesRoleEnabled
{
#Role IDs described at http://msdn.microsoft.com/en-us/library/cc280268(VS.85).aspx
$getRDS = Get-WmiObject Win32_ServerFeature -Filter "ID=18"
if($getRDS -ne $null)
{
$scriptenv.IsTerminalServicesRoleEnabled = $true
}
}
# Easy Print printer driver for printer redirection is enabled.
# http://blogs.msdn.com/b/rds/archive/2009/09/28/using-remote-desktop-easy-print-in-windows-7-and-windows-server-2008-r2.aspx
function Check-IsEasyPrintPrinterRedirectionEnabled
{
$registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services"
if (Test-Path -Path $registryPath)
{
if ((Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue).UseUniversalPrinterDriverFirst -ne "4")
{
$scriptenv.IsEasyPrintPrinterRedirectionEnabled = $true;
}
}
}
# http://blogs.technet.com/b/perfguru/archive/2008/06/25/terminal-server-easy-print.aspx
function Check-IsFileVersionLowerThanRequired
{
$systemdirectory = (Get-WmiObject Win32_OperatingSystem).SystemDirectory
if (Test-Path $systemdirectory\spool\drivers)
{
$files = Get-ChildItem $systemdirectory\spool\drivers -filter "Tsprint.dll" -recurse
if($files -ne $null)
{
foreach ($file in $files)
{
$strversioninfo = "{0}.{1}.{2}.{3}" -f $file.VersionInfo.FileMajorPart, $file.VersionInfo.FileMinorPart, $file.VersionInfo.FileBuildPart, $file.VersionInfo.FilePrivatePart
$versioninfo = [Version]$strversioninfo;
if ($versioninfo -lt [Version]"6.1.7601.21896")
{
$scriptenv.IsFileVersionLowerThanRequired = $true;
break;
}
}
}
}
}
function AdvisorRule($scriptargs, $scriptoutput)
{
trap [Exception] {
$scriptenv.RuntimeError = $true
continue;
}
# Initialize parameters
$scriptoutput.HasIssue = $false
# Detection Logic
if($scriptenv.IsWindowsServer2008R2Sp1Env)
{
Check-IsTerminalServicesRoleEnabled
if($scriptenv.IsTerminalServicesRoleEnabled)
{
Check-IsEasyPrintPrinterRedirectionEnabled
if($scriptenv.IsEasyPrintPrinterRedirectionEnabled)
{
Check-IsFileVersionLowerThanRequired
if($scriptenv.IsFileVersionLowerThanRequired)
{
if ($scriptenv.RuntimeError -eq $false)
{
$scriptoutput.HasIssue = $true
}
}
}
}
}
}
AdvisorRule $scriptargs $scriptoutput
# set the output
$mom = new-object -comobject "MOM.ScriptAPI"
$bag = $mom.CreatePropertyBag()
if ($scriptoutput.HasIssue -ne $null)
{
$bag.AddValue("HasIssue", $scriptoutput.HasIssue)
}
$bag
</ScriptBody>
<SnapIns/>
<TimeoutSeconds>300</TimeoutSeconds>
<Schedule>86393</Schedule>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<Not>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Not>
</SuccessExpression>
</Configuration>
</UnitMonitor>