WMIC kbox script
I'm trying to run this simple statement to rename a machine though KACE:
wmic.exe computersystem where caption='loanerssd7x64' rename ssdloaner7x64
The command works fine when I manually do it, but I can not get it to run through KACE properly. Any ideas on what I can do here?
-Thanks
Answers (2)
You are doing one or two things wrong.
first the syntax is " qoutes around the parameters and ' quotes around the items.
this is becuase you can use multiple operators and then wmi knows the rules.
as an example: where "name like 'Java 6%%' or name like 'Java 7%%' and name != 'Java 7 Update 51'"
so you want to use this in your script:
/c wmic.exe computersystem where "caption='loanerssd7x64'" rename ssdloaner7x64
and the second mistake you may be making is if the machine is in a domain you must use credentials that have domain rights to rename a machine object.
Comments:
-
I gave that a go to, but still not getting the object change.
Output Log
Running as: andrew.shirkey
Launched Process: CMD.EXE
Activity Log
Launching program: 'C:\Windows\System32\CMD.EXE' '/c wmic.exe computersystem where "caption='loanerssd7x64" rename ssdloaner7x64' wait='false' - revsmitty 10 years ago-
I ran the above script on my machine, it failed the first time since it ran as system and the machine is in the domain. As soon as I used domain credentials in the run as it worked. - SMal.tmcc 10 years ago
-
also you do not have the closing single quote after loanerssd7x64. I only see the double, you need both '" - SMal.tmcc 10 years ago
-
oh I see what you did, you put the single quote close after the rename, it needs to be after the where statement.
/c wmic.exe computersystem where "caption='loanerssd7x64'" rename ssdloaner7x64 - SMal.tmcc 10 years ago
-
Thanks! I have successfully been able to do it through KACE. - revsmitty 10 years ago
Since WMIC is a command line utility, you may need to execute it using CMD /C, rather than trying to execute WMIC.EXE directly. Something like this:
Comments:
-
I tried exactly like you mentioned. With quotes around the statement and without, but the machine name still stays the same after reboot.
Activity Log
Launching program: 'C:\Windows\System32\CMD.EXE' '/c wmic.exe computersystem where caption='loanerssd7x64' rename ssdloaner7x64' wait='false' - revsmitty 10 years ago-
that's very odd... I wonder if WMIC doesn't like running from the SYSTEM account. Have you tried setting to run as a specific user? - BHC-Austin 10 years ago
-
Just tried it in this configuration using the local administrator account. Still not taking the name change:
Launching program: 'C:\Windows\System32\CMD.EXE' '/c wmic.exe computersystem where caption='loanerssd7x64' rename ssdloaner7x64' wait='false' - revsmitty 10 years ago -
The only other suggestion I can think of would be to put the WMIC command in a batch file - BHC-Austin 10 years ago
-
Bah, appears running as a batch file doesn't work either. Was able to redirect some logs and appears the issue is that it isn't being ran in an elevated prompt. :(
Do you know anyway around that? - revsmitty 10 years ago -
Shouldn't be an issue if it's running from either the SYSTEM account or local admin. It could be a UAC issue. We had to set UAC policies:
- User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode = Elevate w/o Prompting
- User Account Control: Run all administrators in Admin Approval Mode = Enabled - BHC-Austin 10 years ago -
I'll change the UAC settings on this one machine and try again. Thanks for all the insight. - revsmitty 10 years ago
-
Just to give you an update. Manipulating the UAC settings to your suggestions didn't give a positive result with the script - revsmitty 10 years ago