Powershell 如何运行AdamJ';服务器2016 Core上的WSUS自动维护脚本

Powershell 如何运行AdamJ';服务器2016 Core上的WSUS自动维护脚本,powershell,windows-server-2016,Powershell,Windows Server 2016,我的WSUS服务器运行的server 2016 Core edition没有GUI,因此所有内容都必须通过powershell安装。当我运行Adamj_Clean-WSUS.ps1-FirstRun时,错误是: 术语“sqlcmd”无法识别… Executing ComputerObjectCleanup Executing WSUSDBMaintenance 11 Job11 BackgroundJob Failed False

我的WSUS服务器运行的server 2016 Core edition没有GUI,因此所有内容都必须通过powershell安装。当我运行
Adamj_Clean-WSUS.ps1-FirstRun
时,错误是:

术语“sqlcmd”无法识别…

Executing ComputerObjectCleanup
Executing WSUSDBMaintenance
11     Job11           BackgroundJob   Failed        False           localhost            sqlcmd -S np:\\.\pipe\...
The term 'sqlcmd' is not recognized as the name of a cmdlet...

You cannot call a method on a null-valued expression.
At C:\Users\user\Documents\Adamj_Clean-WSUS.ps1:2480 char:9
...
You cannot call a method on a null-valued expression.
At C:\Users\user\Documents\Adamj_Clean-WSUS.ps1:2482 char:9
+         $Script:AdamjWSUSDBMaintenanceOutputHTML += $AdamjWSUSDBMaint ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Executing WSUSServerCleanupWizard
_
运行数小时后,必须关闭窗口才能停止此操作。

下载ODBC驱动程序和SQL命令行实用程序

将文件复制到核心服务器 一种方法是将它们放置到另一台服务器上的共享中,然后装载该共享:

New-PSDrive -Name T -PSProvider FileSystem -Root \\<server_IP>\<share_name> -Credential <domain>\<user>
cp T:\<folder>\msodbcsql.msi.msi .
cp T:\<folder>\MsSqlCmdLnUtils.msi .
cp T:\<folder>\Clean-WSUS.ps1 .
验证日志:

Get-Content -path .\msodbcsql.log
Get-Content -path .\MsSqlCmdLnUtils.log
安装sqlcmd 验证日志:

Get-Content -path .\msodbcsql.log
Get-Content -path .\MsSqlCmdLnUtils.log
设定路径 这是安装我的SQLCMD.EXE的地方。YMMV:

$env:Path += ";C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\"
执行脚本 如脚本中所述(您已经阅读了注释并设置了变量,对吗?),请首先运行以下命令:

PowerShell.exe -ExecutionPolicy Bypass
然后:


提示:要使
sqlcmd
成为有效的命令,您需要安装什么?
Clean-WSUS.ps1 -FirstRun