Powershell, WMI, Local Computer Description, and value out of range error...
Summary:
Needed to update local computer description on servers that I own. Easy peasy w/ powershell, or so I thought.
PreRequisites:
Needed to update local computer description on servers that I own. Easy peasy w/ powershell, or so I thought.
PreRequisites:
- Powershell 2.0+
- Quest.ActiveRoles.AdManagement Snapin
- SysInternal PSExec
Details:
Windows Server 2008 and 'Vista' based kernel systems seem to have some kind of WMI bug. Searching the web has turned up only a mention of something regarding the use of "ItemIndex". I'm @ a loss. This script will work for 2008 R2 systems and the only work around appears to make use of sysinternals psexec cmd to call out the net config command on the local system.
Add-PSSnapin quest.activeroles.admanagement
$servers = Get-QADComputer -Name "someprefix*"
$Description = "Something I want to insert"
foreach ($computer in $servers)
{
# Simply a check to see whether the system is active or not.
$Ping = Get-WmiObject Win32_PingStatus -Filter "Address = '$($computer.name)'" | Select StatusCode
If ($Ping.StatusCode -eq 0)
{
# This will work for all Windows versions.
# I'm calling the live version, but for speed you may want to download it to your local system.
$computer.Name
\\live.sysinternals.com\tools\psexec.exe \\$computer.name net config server /srvcomment "$($Zone)"
# This will work for 2008 R2 systems and above
# It will return a "Value out of range" error on 2008 systems.
Set-WmiInstance -ComputerName $computer.Name -Path Win32_OperatingSystem=@ -Arguments @{description=$Description}
}
else {
Write-Host "$($computer.name) unreachable"
}
}
Value out of Range issue:
This error really bothers me even if it is for a relatively small problem. Here is what occurs:
- powershell returns the expected data in the description field.
- When attempting to modify the value locally and remotely returns a "value out of range" error.
- The type is string and I don't see any reason why it shouldn't update.
- Only appears to affect 'Vista' based Operating Systems, such as Windows 2008 Server.
It's most definitely a WMI problem, but I'm rather stumped.
Comments