我正在与WSUS进行斗争,并试图建立一个脚本来管理我们远程站点中多个服务器上的SUSDB维护,我们有多个版本和多个操作系统上的服务器,因此它变得有点复杂,更新的服务器(后2008R2)工作时没有任何问题,但是,Server 2008有一个问题:
我在本地或在交互式远程会话中运行它,它按照预期工作,但是如果我嵌套调用命令以在远程会话中运行它,如下所示,它会出现以下错误:
HResult 0x2,第16级,状态1
命名管道提供程序:无法打开到Server 2的连接。
Sqlcmd: Error: Microsoft本机客户端10.0 :在建立到Server的连接时发生了与网络相关或特定于实例的错误。找不到或无法访问服务器。检查实例名称是否正确,以及Server是否配置为允许远程连接。有关详细信息,请参阅Server联机丛书。
Sqlcmd:错误:本机客户端10.0 :登录超时过期
我已经搜寻了好几天,尝试了所有我能想到的排列方式,但我现在拥有的是:
$SQLPath = "C:\Users\<username>\Documents\SQL Server Management Studio\"
$SQLfile = "SUSDB-ReIndex.sql"
$WsusSvrs = ("WSUS-Site1","WSUS-Site7","WSUS-Site13","WSUS-Site14","WSUS-Site15")
$ErrorActionPreference = "Stop"
$results = @()
Foreach ($WSUSSvr in $WSUSSvrs) {
Try {
$sess = New-PSSession -ComputerName $WSUSSvr -EnableNetworkAccess -ErrorAction Stop
}
Catch {
continue;
}
$output = Invoke-Command -Session $sess -ScriptBlock {
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
If((Get-Command SQLcmd.exe -ErrorAction SilentlyContinue)-eq "") {
$NoSQLCmd = new-object System.IO.FileNotFoundException("SQLcmd is not Installed on this machine, please install the appropriate version and try again")
Throw $NoSQLCmd
}
$Output = New-Object psobject
$OSVerStr = (Gwmi win32_operatingsystem).version.split(".")
[single]$OS = [convert]::ToSingle(($OSVerStr[0],$OSVerStr[1] -join "."))
$Output | Add-Member -MemberType NoteProperty -Name OSVer -Value $OS
if ($OS -gt 6.1) {
$conStr = "\\.\pipe\Microsoft##WID\tsql\query"
}
Else {
$conStr = 'np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query'
}
if(Test-Path "$using:SQLPath\$Using:SQLfile") {
$cmd = "sqlcmd.exe -S $ConStr -i '$Using:SQLPath\$Using:SQLfile' -d 'SUSDB' -E -o 'C:\temp \$Using:WSUSSvr-reindexout.txt'"
Invoke-Expression $cmd
$output | Add-Member -MemberType NoteProperty -Name Message -Value "done"
}
else {
$output | Add-Member -MemberType NoteProperty -Name Message -Value "Unable to find $Using:sqlfile"
}
$Output
} -ArgumentList $SQLPath,$SQLfile,$WSUSSvr
$results += $output
if(test-path "\\$wsussvr\C$\temp\$WSUSSvr-reindexout.txt") {
cp "\\$wsussvr\C$\temp\$WSUSSvr-reindexout.txt" "D:\wsus-reports\" -Force
}
If( $sess.State -eq "Opened" ) { Remove-PSSession $sess }
}
$results | ft我知道我们现在应该被拍摄到2008年的盒子,但有一个利基产品供应商和一些预算问题,以取代盒子。
发布于 2021-08-18 12:44:59
在第35行,我看到以下内容
Else {
$conStr = 'np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query'
}您能试着在不使用np:的情况下运行它吗?
Else {
$conStr = '\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query'
}https://stackoverflow.com/questions/67574179
复制相似问题