我当前正试图通过命令行强制WSUS拒绝更新,因为它过载,因此我无法访问管理单元。这是我在网上找到的代码,但是唯一的问题是我的服务器具有名称中的破折号并弄乱了代码。我尝试将qoutations放在名称周围,但仍然在第三行的“:”后面吐出无效字符
编辑:新错误 无效的URI:无法解析主机名。在Microsoft.UpdateServices.Administration.AdminProxy.GetupdateServer(String serverName,Boolean useSecureConnection,Int32 portnumber)处在Microsoft.UpdateServices.Administration.AdminProxy.GetupdateServer(String serverName,Boolean useSecureConnection,Int32 portnumber)在Callsite.Target(Closure,Callsite,Type,Object,Object ,对象)
#Change server name and port number and $True if it is on SSL
$Computer = $env:common-n-sccm2012
$Domain = $env:airplane.black.low.com
$FQDN = "$Computer" + "." + "$Domain"
[String]$updateServer1 = $FQDN
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 8530
# Load .NET assembly
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$count = 0
# Connect to WSUS Server
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$useSecureConnection,$portNumber)
write-host "<<<Connected sucessfully >>>" -foregroundcolor "yellow"
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$u=$updateServer.GetUpdates($updatescope )
foreach ($u1 in $u )
{
if ($u1.IsSuperseded -eq 'True')
{
write-host Decline Update : $u1.Title
$u1.Decline()
$count=$count + 1
}
}
write-host Total Declined Updates: $count
trap
{
write-host "Error Occurred"
write-host "Exception Message: "
write-host $_.Exception.Message
write-host $_.Exception.StackTrace
exit
}
# EOF
答案 0 :(得分:0)
我认为您的意思是此行弹出错误:
$Computer = $env:common-n-sccm2012
因为您正在尝试获取名称中带有短划线的环境变量。您可以尝试将其格式化为:
$Computer = ${env:common-n-sccm2012}
如何
我认为您正在'环境化'硬编码的值,这是实际的问题。
很难相信您确实拥有名称为common-n-sccm2012
和airplane.black.low.com
之类的环境变量。
要从您所在的计算机上获取实际的完全合格域名,可以执行以下操作:
$Computer = $env:COMPUTERNAME # --> "common-n-sccm2012"
$Domain = $env:USERDNSDOMAIN # --> "airplane.black.low.com"
$FQDN = "$Computer" + "." + "$Domain" # --> "common-n-sccm2012.airplane.black.low.com"
(或一行:$FQDN = "$env:COMPUTERNAME.$env:USERDNSDOMAIN"
)
您还可以使用WMI获取此FQDN:
$FQDN = (Get-WmiObject win32_computersystem).DNSHostName + "." + (Get-WmiObject win32_computersystem).Domain
您可以阅读有关环境变量here
的信息。