0
$servername='DC1'
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($servername,$False)

这是我要运行的 powershell 命令。但得到一个例外 -

    Exception calling "GetUpdateServer" with "2" argument(s): "The type initializer for 
'Microsoft.UpdateServices.Internal.Constants' threw an exception."
At line:3 char:1
+ $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : TypeInitializationException

当我尝试引用 Microsoft.UpdateServices.Administration.dll 并尝试使用 GetUpdateServer 方法时,我在 AdminProxy 类中找不到该方法。这是代码行-

    using Microsoft.UpdateServices.Administration;
using Microsoft.UpdateServices;
using System.Runtime.InteropServices;
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")]
public sealed class AdminProxy
{

}

namespace WindowsApplication2
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IUpdateServer obj;
            obj = AdminProxy.GetUpdateServer();


        }
    }
4

1 回答 1

0

正如用户 boeprox 在评论中指出的那样,您需要以管理员身份运行 PowerShell 控制台。

于 2019-02-06T10:09:03.907 回答