WMI Perms/Add user to local groups/script works, how to add "loop'?

Hello,

I am trying to use the script I found on the post below, but I have to set the WMI permissions and add the account I need to use to hundreds of servers.

I got stuck trying to use the functions with a loop so I can run it against a list of servers in 1 instance and then in another instance I want to query the domain for server Operating Systems and then run the script for all servers found.

Can anyone help me with this please?

The link to the script I’m trying to use is below, I did try to ask the author a couple times but didn’t get a reply.
I’m not sure if this is the best method to do this task, so if anyone has suggestions please let me know!

Which part do you need help with?

Assuming you can retrieve a list of computer names, and assuming his script is named ChangeWmi.ps1, then you could do something like:

Get-ADComputer -filter * | Select -expand name | ForEach { .\ChangeWmi.ps1 -computername $_ -add -user whatever -domain whatever }

Obviously, your Get-ADComputer command would differ since you don’t want ALL domain computers. Get-ADComputer comes from the MS ActiveDirectory module; you would need that, of course.

I have to actually start somewhere else I think, this script isn’t working on 2003 servers.

I’m stuck now trying to find something that will let me set wmi permissions on 2003 servers.

I also think I need to set some user rights assignments and can’t find any method of doing that on 2003, 2008, 2008R2 via script and I can’t do that with a GPO as it will overwrite the existing settings.

If anyone can offer any help I’d really appreciate it.

Don - one other quick question, why does the username have to be added to the command line if it’s in the script and the same for the domain?

Also, what’s the best way to add a ps1 file as a function to another script such as I tried in this case?

Well, generally speaking, you simply enclose the contents of a script in a function declaration:

function Do-Whatever {
}

To turn the contents of a script into a function. The function can then be pasted into another script, made into a script module, or whatever you kids do these days.

In terms of why the username has to be added - it’s an input parameter of the script you linked to. The script expects that info. So if you’re going to use that script verbatim, you need to give it the information it wants. If you’ve hardcoded it or something, then maybe not.