首页 \ 问答 \ 应用PowerShell DSC配置时出错(Error when applying PowerShell DSC configuration)

应用PowerShell DSC配置时出错(Error when applying PowerShell DSC configuration)

我有一个简单的PowerShell DSC配置块,可确保用户帐户不存在,并且当我尝试使用Start-DscConfiguration将其应用于本地系统时,我收到类似于以下内容的错误消息:

WS-Management服务无法处理请求。 WMI服务返回了“访问被拒绝”错误。

我怎样才能成功应用DSC配置?

这是我正在使用的配置块:

configuration MyConfig {
    User Trevor2 {
        UserName = 'Trevor2';
        Ensure = 'Absent';
    }
}

$Path = 'c:\dsc\MyConfig';
MyConfig -OutputPath $Path;

Start-DscConfiguration -Wait -Verbose -Path $Path;
# Clean up MOF files
Remove-Item -Path $Path -Recurse;

I have a simple PowerShell DSC configuration block that ensures that a user account does not exist, and when I attempt to apply it to the local system using Start-DscConfiguration, I am receiving an error message similar to the following:

The WS-Management service cannot process the request. The WMI service returned an 'access denied' error.

How can I apply the DSC configuration successfully?

Here is the configuration block I am using:

configuration MyConfig {
    User Trevor2 {
        UserName = 'Trevor2';
        Ensure = 'Absent';
    }
}

$Path = 'c:\dsc\MyConfig';
MyConfig -OutputPath $Path;

Start-DscConfiguration -Wait -Verbose -Path $Path;
# Clean up MOF files
Remove-Item -Path $Path -Recurse;

原文:https://stackoverflow.com/questions/25560219
更新时间:2021-10-13 07:10

最满意答案

有了您提供的额外细节,前两个答案将无法工作。 你需要的是一种被称为单元变体的类型,然后你可以拥有这些类型的矢量。 例如:-

enum CellType
{
  Int,
  Float,
  // etc
};

class Cell
{
  CellType type;
  union
  {
    int i;
    float f;
    // etc
  };
};

class Vector
{
  vector <Cell> cells;
};

然而,这是一种添加新类型的痛苦,因为它需要大量的代码来维护。 替代方案可以使用具有公共基类的单元格模板: -

class ICell
{
  // list of cell methods
};

template <class T>
class Cell : public ICell
{
  T data;
  // implementation of cell methods
};

class Vector
{
  vector <ICell *> cells;
};

这可能会更好,因为您初始更新的代码更少以添加新的单元格类型,但必须在单元格矢量中使用指针类型。 如果按值存储单元格,则vector <ICell> ,则由于对象分割而丢失数据。


With the extra detail you've provided, the first two answers won't work. What you require is a type known as a variant for the cell and then you can have a vector of those. For example:-

enum CellType
{
  Int,
  Float,
  // etc
};

class Cell
{
  CellType type;
  union
  {
    int i;
    float f;
    // etc
  };
};

class Vector
{
  vector <Cell> cells;
};

This, however, is a pain to add new types to as it requires a lot of code to maintain. An alternative could use the cell template with a common base class:-

class ICell
{
  // list of cell methods
};

template <class T>
class Cell : public ICell
{
  T data;
  // implementation of cell methods
};

class Vector
{
  vector <ICell *> cells;
};

This might work better as you have less code initially to update to add a new cell type but you have to use a pointer type in the cells vector. If you stored the cell by value, vector <ICell>, then you will lose data due to object slicing.

相关问答

更多
  • 有了您提供的额外细节,前两个答案将无法工作。 你需要的是一种被称为单元变体的类型,然后你可以拥有这些类型的矢量。 例如:- enum CellType { Int, Float, // etc }; class Cell { CellType type; union { int i; float f; // etc }; }; class Vector { vector cells; }; 然而,这是一种添加新类型的痛苦,因为它需要 ...
  • 尝试这个: template T getTransform(const T& vec) { T res; res.resize(vec.size()); for (size_t i = 0; i < size_t(vec.size()); ++i) { res[i] = vec[i]*3.14; } return res; } Try this: template T getTrans ...
  • 我确定你知道, students[0]的表达意味着你试图访问vector第一个项目。 但是,要访问第一个项目,您必须先添加第一个项目。 很简单,在尝试使用向量中的任何内容之前,添加对vector::push_back的调用。 或者,通过声明向量 vector students(/*number of default Students here*/); 还有其他方法,但只要确保你有你想要使用的东西。 具体来说,传递给[]操作的索引必须满足条件0 <= index && index < st ...
  • 在访问依赖于模板参数的类型时,必须预先添加typename以使分析器清楚该类型是否为类型。 for(typename Vector::iterator it = vector.begin(); it != vector.end(); ++it) Vector :: iterator可能是一个编译时常数,编译器在实例化时间之前无法知道。 这就是为什么你必须明确地告诉它。 When accessing types that depend on a template parameter, you must pr ...
  • 您必须提供如下定义: template class Vector { // vector stuff static const Vector c_NullVector; } template const Vector Vector::c_NullVector; 如果您可以提出通用初始化,则可以将其放在定义中。 You must provide a definition as follows: template
  • 当你调用container.reserve(3); 增加向量的容量(内部存储的大小),但向量保持为空。 operator[]不插入元素,所以当你这样做时: container.reserve(3); container[0] = a; container[1] = b; container[2] = c; 您正在访问向量中实际不存在的某些元素,此后向量仍为空。 执行所需操作的方法是resize() ,这实际上会增加向量的大小。 您在testLocally方法中调用的构造函数设置向量的初始大小,而不是它的初 ...
  • 您需要在头文件中定义模板,而不是在.cpp文件中。 该标准要求模板定义存在于声明的每个翻译单元中(如果使用)。 You need to define the template in the header file not in the .cpp file. The standard requires that the template definition is present in every translation unit it is declared in (if used).
  • boost :: mpl做了这样的事情(这是他们绑定参数的想法)。 但是,你必须做出许多假设才能使它工作,比如使用; template foo { }; typedef foo< int_<4> > my_foo_4; 代替 template foo { }; typedef foo<4> my_foo_4; 不必为所有int,char,bool等组合提供重载。 我想不出任何比boost :: mpl方法更有效的方法,总的来说,我认为任何方法都会遇到很多问题; 类模板 ...
  • 您可以使用特征样式助手类。 template CVectorTraits {}; template<> CVectorTraits { typedef Point3d PointType; } template<> CVectorTraits { typedef Point3f PointType; } template class CVector3 { CVector3 &normalize(); // ...
  • 你的写作addstuff()将尝试解析Set addstuff() ,这是毫无意义的。 addstuff()允许你将std::string s添加到你的set中,但是a.add(1)会失败,因为文字不能隐式转换为字符串类型。 addstuff() 确实有效,但这是一个快乐的巧合。 add(1)在该实例中具有正确的类型以添加到Set 。 您可以构建一个类Foo ,它具有一个字符串和一个整数的非显式构造函数,并使其成为您的模板类型: addstu ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)