How can I update LDAP attributes on the “ds_computer” class through WMI using PowerShell
I am unable to update an instance of the ds_computer WMI class within the rootdirectoryldap namespace using PowerShell.
However I am able to update the same instance using C#. Here is my working C# code:
string computerName = Environment.GetEnvironmentVariable("ComputerName");
var connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.EnablePrivileges = true;
connectionOptions.Timeout = new TimeSpan(0, 0, 0, 5, 0);
var managementScope = new ManagementScope();
managementScope.Path.Server = computerName;
managementScope.Path.NamespacePath = @"ROOTdirectoryLDAP";
managementScope.Options = connectionOptions;
managementScope.Options.Context.Add("__ProviderArchitecture", 64);
managementScope.Connect();
var context = new ManagementNamedValueCollection();
context.Add("__PUT_EXT_PROPERTIES", new string {"DS_displayName"});
context.Add("__PUT_EXTENSIONS", true);
context.Add("__PUT_EXT_CLIENT_REQUEST", true);
var putOptions = new PutOptions();
putOptions.Context = context;
putOptions.UseAmendedQualifiers = false;
putOptions.Type = PutType.UpdateOnly;
string commandText = string.Format("SELECT * FROM ds_computer WHERE DS_name='{0}'", computerName);
var managementObjectSearcher = new ManagementObjectSearcher(managementScope, new ObjectQuery(commandText));
var managementObjectCollection = managementObjectSearcher.Get();
var managementObject = managementObjectCollection.Cast<ManagementObject>().FirstOrDefault();
managementObject.SetPropertyValue("DS_displayName", "cs-test");
managementObject.Put(putOptions);
Translating this code to PowerShell yields the following result:
PS > $computerName = $env:COMPUTERNAME
PS > $connectionOptions = [System.Management.ConnectionOptions]::New()
PS > $connectionOptions.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
PS > $connectionOptions.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy
PS > $connectionOptions.EnablePrivileges = $true
PS > $connectionOptions.Timeout = [System.TimeSpan]::New(0, 0, 0, 5, 0)
PS > $managementScope = [System.Management.ManagementScope]::New()
PS > $managementScope.Path.Server = $computerName
PS > $managementScope.Path.NamespacePath = "ROOTdirectoryLDAP"
PS > $managementScope.Options = $connectionOptions
PS > $managementScope.Options.Context.Add("__ProviderArchitecture", 64)
PS > $managementScope.Connect()
PS > $context = [System.Management.ManagementNamedValueCollection]::New()
PS > $context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
PS > $context.Add("__PUT_EXTENSIONS", $true)
PS > $context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
PS > $putOptions = [System.Management.PutOptions]::New()
PS > $putOptions.Context = $context
PS > $putOptions.UseAmendedQualifiers = $false
PS > $putOptions.Type = [System.Management.PutType]::UpdateOnly
PS > $commandText = "SELECT * FROM ds_computer WHERE DS_name='$computerName'"
PS > $managementObjectSearcher = [System.Management.ManagementObjectSearcher]::New($managementScope, [System.Management.ObjectQuery]::New($commandText))
PS > $managementObjectCollection = $managementObjectSearcher.Get()
PS > $managementObject = [Linq.Enumerable]::FirstOrDefault([System.Management.ManagementObject]$managementObjectCollection)
PS > $managementObject.SetPropertyValue("DS_displayName", "ps-test")
PS > $managementObject.Put($putOptions)
Exception calling "Put" with "1" argument(s): "Value cannot be null.
Parameter name: pUnk"
At line:1 char:1
+ $managementObject.Put($putOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Of course I would rather be able to simply use the provided cmdlets Get-WmiObject/Set-WmiInstance, but unfortunately this also fails with the following result:
PS > $managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Authentication PacketPrivacy -Impersonation Impersonate -EnableAllPrivileges -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-WmiInstance -InputObject $managementObject -PutType UpdateOnly -Arguments @{DS_displayName="cmdlet1-test"}
Set-WmiInstance : Generic failure
At line:1 char:1
+ Set-WmiInstance -InputObject $x -PutType UpdateOnly
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WmiInstance], ManagementException
+ FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance
I also tried using the Get-CimInstance/Set-CimInstance cmdlets and got the same incredibly helpful "Generic Failure" message:
PS > $cimInstance = Get-CimInstance -Namespace "ROOTdirectoryLDAP" -ClassName "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-CimInstance -InputObject $cimInstance -Property @{DS_displayName="cmdlet2-test"}
Set-CimInstance : Generic failure
At line:1 char:1
+ Set-CimInstance -InputObject $x -Property @{DS_displayName="cmdlet2-test"} -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ds_computer (AD...tyDomainPCG...):CimInstance) [Set-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041001,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
c# .net powershell ldap wmi
add a comment |
I am unable to update an instance of the ds_computer WMI class within the rootdirectoryldap namespace using PowerShell.
However I am able to update the same instance using C#. Here is my working C# code:
string computerName = Environment.GetEnvironmentVariable("ComputerName");
var connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.EnablePrivileges = true;
connectionOptions.Timeout = new TimeSpan(0, 0, 0, 5, 0);
var managementScope = new ManagementScope();
managementScope.Path.Server = computerName;
managementScope.Path.NamespacePath = @"ROOTdirectoryLDAP";
managementScope.Options = connectionOptions;
managementScope.Options.Context.Add("__ProviderArchitecture", 64);
managementScope.Connect();
var context = new ManagementNamedValueCollection();
context.Add("__PUT_EXT_PROPERTIES", new string {"DS_displayName"});
context.Add("__PUT_EXTENSIONS", true);
context.Add("__PUT_EXT_CLIENT_REQUEST", true);
var putOptions = new PutOptions();
putOptions.Context = context;
putOptions.UseAmendedQualifiers = false;
putOptions.Type = PutType.UpdateOnly;
string commandText = string.Format("SELECT * FROM ds_computer WHERE DS_name='{0}'", computerName);
var managementObjectSearcher = new ManagementObjectSearcher(managementScope, new ObjectQuery(commandText));
var managementObjectCollection = managementObjectSearcher.Get();
var managementObject = managementObjectCollection.Cast<ManagementObject>().FirstOrDefault();
managementObject.SetPropertyValue("DS_displayName", "cs-test");
managementObject.Put(putOptions);
Translating this code to PowerShell yields the following result:
PS > $computerName = $env:COMPUTERNAME
PS > $connectionOptions = [System.Management.ConnectionOptions]::New()
PS > $connectionOptions.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
PS > $connectionOptions.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy
PS > $connectionOptions.EnablePrivileges = $true
PS > $connectionOptions.Timeout = [System.TimeSpan]::New(0, 0, 0, 5, 0)
PS > $managementScope = [System.Management.ManagementScope]::New()
PS > $managementScope.Path.Server = $computerName
PS > $managementScope.Path.NamespacePath = "ROOTdirectoryLDAP"
PS > $managementScope.Options = $connectionOptions
PS > $managementScope.Options.Context.Add("__ProviderArchitecture", 64)
PS > $managementScope.Connect()
PS > $context = [System.Management.ManagementNamedValueCollection]::New()
PS > $context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
PS > $context.Add("__PUT_EXTENSIONS", $true)
PS > $context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
PS > $putOptions = [System.Management.PutOptions]::New()
PS > $putOptions.Context = $context
PS > $putOptions.UseAmendedQualifiers = $false
PS > $putOptions.Type = [System.Management.PutType]::UpdateOnly
PS > $commandText = "SELECT * FROM ds_computer WHERE DS_name='$computerName'"
PS > $managementObjectSearcher = [System.Management.ManagementObjectSearcher]::New($managementScope, [System.Management.ObjectQuery]::New($commandText))
PS > $managementObjectCollection = $managementObjectSearcher.Get()
PS > $managementObject = [Linq.Enumerable]::FirstOrDefault([System.Management.ManagementObject]$managementObjectCollection)
PS > $managementObject.SetPropertyValue("DS_displayName", "ps-test")
PS > $managementObject.Put($putOptions)
Exception calling "Put" with "1" argument(s): "Value cannot be null.
Parameter name: pUnk"
At line:1 char:1
+ $managementObject.Put($putOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Of course I would rather be able to simply use the provided cmdlets Get-WmiObject/Set-WmiInstance, but unfortunately this also fails with the following result:
PS > $managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Authentication PacketPrivacy -Impersonation Impersonate -EnableAllPrivileges -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-WmiInstance -InputObject $managementObject -PutType UpdateOnly -Arguments @{DS_displayName="cmdlet1-test"}
Set-WmiInstance : Generic failure
At line:1 char:1
+ Set-WmiInstance -InputObject $x -PutType UpdateOnly
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WmiInstance], ManagementException
+ FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance
I also tried using the Get-CimInstance/Set-CimInstance cmdlets and got the same incredibly helpful "Generic Failure" message:
PS > $cimInstance = Get-CimInstance -Namespace "ROOTdirectoryLDAP" -ClassName "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-CimInstance -InputObject $cimInstance -Property @{DS_displayName="cmdlet2-test"}
Set-CimInstance : Generic failure
At line:1 char:1
+ Set-CimInstance -InputObject $x -Property @{DS_displayName="cmdlet2-test"} -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ds_computer (AD...tyDomainPCG...):CimInstance) [Set-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041001,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
c# .net powershell ldap wmi
add a comment |
I am unable to update an instance of the ds_computer WMI class within the rootdirectoryldap namespace using PowerShell.
However I am able to update the same instance using C#. Here is my working C# code:
string computerName = Environment.GetEnvironmentVariable("ComputerName");
var connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.EnablePrivileges = true;
connectionOptions.Timeout = new TimeSpan(0, 0, 0, 5, 0);
var managementScope = new ManagementScope();
managementScope.Path.Server = computerName;
managementScope.Path.NamespacePath = @"ROOTdirectoryLDAP";
managementScope.Options = connectionOptions;
managementScope.Options.Context.Add("__ProviderArchitecture", 64);
managementScope.Connect();
var context = new ManagementNamedValueCollection();
context.Add("__PUT_EXT_PROPERTIES", new string {"DS_displayName"});
context.Add("__PUT_EXTENSIONS", true);
context.Add("__PUT_EXT_CLIENT_REQUEST", true);
var putOptions = new PutOptions();
putOptions.Context = context;
putOptions.UseAmendedQualifiers = false;
putOptions.Type = PutType.UpdateOnly;
string commandText = string.Format("SELECT * FROM ds_computer WHERE DS_name='{0}'", computerName);
var managementObjectSearcher = new ManagementObjectSearcher(managementScope, new ObjectQuery(commandText));
var managementObjectCollection = managementObjectSearcher.Get();
var managementObject = managementObjectCollection.Cast<ManagementObject>().FirstOrDefault();
managementObject.SetPropertyValue("DS_displayName", "cs-test");
managementObject.Put(putOptions);
Translating this code to PowerShell yields the following result:
PS > $computerName = $env:COMPUTERNAME
PS > $connectionOptions = [System.Management.ConnectionOptions]::New()
PS > $connectionOptions.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
PS > $connectionOptions.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy
PS > $connectionOptions.EnablePrivileges = $true
PS > $connectionOptions.Timeout = [System.TimeSpan]::New(0, 0, 0, 5, 0)
PS > $managementScope = [System.Management.ManagementScope]::New()
PS > $managementScope.Path.Server = $computerName
PS > $managementScope.Path.NamespacePath = "ROOTdirectoryLDAP"
PS > $managementScope.Options = $connectionOptions
PS > $managementScope.Options.Context.Add("__ProviderArchitecture", 64)
PS > $managementScope.Connect()
PS > $context = [System.Management.ManagementNamedValueCollection]::New()
PS > $context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
PS > $context.Add("__PUT_EXTENSIONS", $true)
PS > $context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
PS > $putOptions = [System.Management.PutOptions]::New()
PS > $putOptions.Context = $context
PS > $putOptions.UseAmendedQualifiers = $false
PS > $putOptions.Type = [System.Management.PutType]::UpdateOnly
PS > $commandText = "SELECT * FROM ds_computer WHERE DS_name='$computerName'"
PS > $managementObjectSearcher = [System.Management.ManagementObjectSearcher]::New($managementScope, [System.Management.ObjectQuery]::New($commandText))
PS > $managementObjectCollection = $managementObjectSearcher.Get()
PS > $managementObject = [Linq.Enumerable]::FirstOrDefault([System.Management.ManagementObject]$managementObjectCollection)
PS > $managementObject.SetPropertyValue("DS_displayName", "ps-test")
PS > $managementObject.Put($putOptions)
Exception calling "Put" with "1" argument(s): "Value cannot be null.
Parameter name: pUnk"
At line:1 char:1
+ $managementObject.Put($putOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Of course I would rather be able to simply use the provided cmdlets Get-WmiObject/Set-WmiInstance, but unfortunately this also fails with the following result:
PS > $managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Authentication PacketPrivacy -Impersonation Impersonate -EnableAllPrivileges -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-WmiInstance -InputObject $managementObject -PutType UpdateOnly -Arguments @{DS_displayName="cmdlet1-test"}
Set-WmiInstance : Generic failure
At line:1 char:1
+ Set-WmiInstance -InputObject $x -PutType UpdateOnly
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WmiInstance], ManagementException
+ FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance
I also tried using the Get-CimInstance/Set-CimInstance cmdlets and got the same incredibly helpful "Generic Failure" message:
PS > $cimInstance = Get-CimInstance -Namespace "ROOTdirectoryLDAP" -ClassName "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-CimInstance -InputObject $cimInstance -Property @{DS_displayName="cmdlet2-test"}
Set-CimInstance : Generic failure
At line:1 char:1
+ Set-CimInstance -InputObject $x -Property @{DS_displayName="cmdlet2-test"} -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ds_computer (AD...tyDomainPCG...):CimInstance) [Set-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041001,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
c# .net powershell ldap wmi
I am unable to update an instance of the ds_computer WMI class within the rootdirectoryldap namespace using PowerShell.
However I am able to update the same instance using C#. Here is my working C# code:
string computerName = Environment.GetEnvironmentVariable("ComputerName");
var connectionOptions = new ConnectionOptions();
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.EnablePrivileges = true;
connectionOptions.Timeout = new TimeSpan(0, 0, 0, 5, 0);
var managementScope = new ManagementScope();
managementScope.Path.Server = computerName;
managementScope.Path.NamespacePath = @"ROOTdirectoryLDAP";
managementScope.Options = connectionOptions;
managementScope.Options.Context.Add("__ProviderArchitecture", 64);
managementScope.Connect();
var context = new ManagementNamedValueCollection();
context.Add("__PUT_EXT_PROPERTIES", new string {"DS_displayName"});
context.Add("__PUT_EXTENSIONS", true);
context.Add("__PUT_EXT_CLIENT_REQUEST", true);
var putOptions = new PutOptions();
putOptions.Context = context;
putOptions.UseAmendedQualifiers = false;
putOptions.Type = PutType.UpdateOnly;
string commandText = string.Format("SELECT * FROM ds_computer WHERE DS_name='{0}'", computerName);
var managementObjectSearcher = new ManagementObjectSearcher(managementScope, new ObjectQuery(commandText));
var managementObjectCollection = managementObjectSearcher.Get();
var managementObject = managementObjectCollection.Cast<ManagementObject>().FirstOrDefault();
managementObject.SetPropertyValue("DS_displayName", "cs-test");
managementObject.Put(putOptions);
Translating this code to PowerShell yields the following result:
PS > $computerName = $env:COMPUTERNAME
PS > $connectionOptions = [System.Management.ConnectionOptions]::New()
PS > $connectionOptions.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
PS > $connectionOptions.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy
PS > $connectionOptions.EnablePrivileges = $true
PS > $connectionOptions.Timeout = [System.TimeSpan]::New(0, 0, 0, 5, 0)
PS > $managementScope = [System.Management.ManagementScope]::New()
PS > $managementScope.Path.Server = $computerName
PS > $managementScope.Path.NamespacePath = "ROOTdirectoryLDAP"
PS > $managementScope.Options = $connectionOptions
PS > $managementScope.Options.Context.Add("__ProviderArchitecture", 64)
PS > $managementScope.Connect()
PS > $context = [System.Management.ManagementNamedValueCollection]::New()
PS > $context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
PS > $context.Add("__PUT_EXTENSIONS", $true)
PS > $context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
PS > $putOptions = [System.Management.PutOptions]::New()
PS > $putOptions.Context = $context
PS > $putOptions.UseAmendedQualifiers = $false
PS > $putOptions.Type = [System.Management.PutType]::UpdateOnly
PS > $commandText = "SELECT * FROM ds_computer WHERE DS_name='$computerName'"
PS > $managementObjectSearcher = [System.Management.ManagementObjectSearcher]::New($managementScope, [System.Management.ObjectQuery]::New($commandText))
PS > $managementObjectCollection = $managementObjectSearcher.Get()
PS > $managementObject = [Linq.Enumerable]::FirstOrDefault([System.Management.ManagementObject]$managementObjectCollection)
PS > $managementObject.SetPropertyValue("DS_displayName", "ps-test")
PS > $managementObject.Put($putOptions)
Exception calling "Put" with "1" argument(s): "Value cannot be null.
Parameter name: pUnk"
At line:1 char:1
+ $managementObject.Put($putOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Of course I would rather be able to simply use the provided cmdlets Get-WmiObject/Set-WmiInstance, but unfortunately this also fails with the following result:
PS > $managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Authentication PacketPrivacy -Impersonation Impersonate -EnableAllPrivileges -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-WmiInstance -InputObject $managementObject -PutType UpdateOnly -Arguments @{DS_displayName="cmdlet1-test"}
Set-WmiInstance : Generic failure
At line:1 char:1
+ Set-WmiInstance -InputObject $x -PutType UpdateOnly
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WmiInstance], ManagementException
+ FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance
I also tried using the Get-CimInstance/Set-CimInstance cmdlets and got the same incredibly helpful "Generic Failure" message:
PS > $cimInstance = Get-CimInstance -Namespace "ROOTdirectoryLDAP" -ClassName "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
PS > Set-CimInstance -InputObject $cimInstance -Property @{DS_displayName="cmdlet2-test"}
Set-CimInstance : Generic failure
At line:1 char:1
+ Set-CimInstance -InputObject $x -Property @{DS_displayName="cmdlet2-test"} -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ds_computer (AD...tyDomainPCG...):CimInstance) [Set-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041001,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
c# .net powershell ldap wmi
c# .net powershell ldap wmi
edited Jan 3 at 15:51
jmjohnson85
asked Jan 3 at 15:42
jmjohnson85jmjohnson85
765
765
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I figured it out. The problem was with the array syntax that I was storing in $context["__PUT_EXT_PROPERTIES"]
This doesn't work:
$context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
While this works:
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
So, here is a fully working example for anyone else who may be struggling with this:
$context = [System.Management.ManagementNamedValueCollection]::New()
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
$context.Add("__PUT_EXTENSIONS", $true)
$context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
$putOptions = [System.Management.PutOptions]::New()
$putOptions.Context = $context
$putOptions.UseAmendedQualifiers = $false
$putOptions.Type = [System.Management.PutType]::UpdateOnly
$managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
$managementObject.DS_displayName = "cmdlet-test"
$managementObject.Put($putOptions)
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025491%2fhow-can-i-update-ldap-attributes-on-the-ds-computer-class-through-wmi-using-po%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I figured it out. The problem was with the array syntax that I was storing in $context["__PUT_EXT_PROPERTIES"]
This doesn't work:
$context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
While this works:
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
So, here is a fully working example for anyone else who may be struggling with this:
$context = [System.Management.ManagementNamedValueCollection]::New()
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
$context.Add("__PUT_EXTENSIONS", $true)
$context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
$putOptions = [System.Management.PutOptions]::New()
$putOptions.Context = $context
$putOptions.UseAmendedQualifiers = $false
$putOptions.Type = [System.Management.PutType]::UpdateOnly
$managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
$managementObject.DS_displayName = "cmdlet-test"
$managementObject.Put($putOptions)
add a comment |
I figured it out. The problem was with the array syntax that I was storing in $context["__PUT_EXT_PROPERTIES"]
This doesn't work:
$context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
While this works:
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
So, here is a fully working example for anyone else who may be struggling with this:
$context = [System.Management.ManagementNamedValueCollection]::New()
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
$context.Add("__PUT_EXTENSIONS", $true)
$context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
$putOptions = [System.Management.PutOptions]::New()
$putOptions.Context = $context
$putOptions.UseAmendedQualifiers = $false
$putOptions.Type = [System.Management.PutType]::UpdateOnly
$managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
$managementObject.DS_displayName = "cmdlet-test"
$managementObject.Put($putOptions)
add a comment |
I figured it out. The problem was with the array syntax that I was storing in $context["__PUT_EXT_PROPERTIES"]
This doesn't work:
$context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
While this works:
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
So, here is a fully working example for anyone else who may be struggling with this:
$context = [System.Management.ManagementNamedValueCollection]::New()
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
$context.Add("__PUT_EXTENSIONS", $true)
$context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
$putOptions = [System.Management.PutOptions]::New()
$putOptions.Context = $context
$putOptions.UseAmendedQualifiers = $false
$putOptions.Type = [System.Management.PutType]::UpdateOnly
$managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
$managementObject.DS_displayName = "cmdlet-test"
$managementObject.Put($putOptions)
I figured it out. The problem was with the array syntax that I was storing in $context["__PUT_EXT_PROPERTIES"]
This doesn't work:
$context.Add("__PUT_EXT_PROPERTIES", @("DS_displayName"))
While this works:
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
So, here is a fully working example for anyone else who may be struggling with this:
$context = [System.Management.ManagementNamedValueCollection]::New()
$context.Add("__PUT_EXT_PROPERTIES", [string]("DS_displayName"))
$context.Add("__PUT_EXTENSIONS", $true)
$context.Add("__PUT_EXT_CLIENT_REQUEST", $true)
$putOptions = [System.Management.PutOptions]::New()
$putOptions.Context = $context
$putOptions.UseAmendedQualifiers = $false
$putOptions.Type = [System.Management.PutType]::UpdateOnly
$managementObject = Get-WmiObject -Namespace "rootdirectoryldap" -Class "ds_computer" -Filter "DS_name='$env:COMPUTERNAME'"
$managementObject.DS_displayName = "cmdlet-test"
$managementObject.Put($putOptions)
answered Jan 3 at 15:50
jmjohnson85jmjohnson85
765
765
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025491%2fhow-can-i-update-ldap-attributes-on-the-ds-computer-class-through-wmi-using-po%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
