如何在Server 2016 Core上运行AdamJ的WSUS自动维护脚本

时间:2018-04-04 18:51:33

标签: powershell windows-server-2016

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

The term 'sqlcmd' is not recognized...

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
_

在跑了几个小时之后,不得不杀死窗户停止它。

1 个答案:

答案 0 :(得分:0)

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

https://docs.microsoft.com/en-us/sql/connect/odbc/windows/system-requirements-installation-and-driver-files#installing-microsoft-odbc-driver-for-sql-server

https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility

将文件复制到核心服务器

一种方法是将它们放在另一台服务器上的共享中,然后挂载该共享:

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 .

如何安装msi文件

如果您已经习惯按标签键来完成文件名设置,请考虑&#34;。\&#34;自动添加到文件名前是无辜的,请注意它不是:https://superuser.com/a/1310787/891171

安装odbc驱动程序

msiexec /i msodbcsql.msi /qn IACCEPTMSODBCSQLLICENSETERMS=YES /L*V msodbcsql.log

验证日志:

Get-Content -path .\msodbcsql.log

安装sqlcmd

msiexec /i MsSqlCmdLnUtils.msi /Passive /NoRestart IACCEPTMSSQLCMDLNUTILSLICENSETERMS=YES /L*V MsSqlCmdLnUtils.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

然后:

Clean-WSUS.ps1 -FirstRun