Jump to content

Recommended Posts

Posted

Hi all,

 

I am looking for a way to have one master script instead of having many many scripts.

Basically what is needed is that there is a certain command that has a different user ID for each user in Active Directory. Is it possible to have a script such as:

 

IF username is 'username'

run this command then end,

 

and repeated many times for different user accounts within one script file?

 

Thanks,

Posted (edited)

That's definitely possible and there are a few ways to do it. I'll assume using Powershell to do this as it's what I know best and is going to be more useful to learn (or at least use) in the long run than vbscript or batch (though they both work well and have their place).

 

Assuming you are running roughly the same commands on each user then the easiest way to do it would be to write the script as if you were doing it for one user but have it accept a parameter for the username (or some other identifier of your choice). Once you've got that it's as simple as:

 

 
Import-csv -path "c:\path\to\file.csv" | foreach-object { c:\path\to\script.ps1 -username $_.username}

 

You can change the -username to whatever you call your parameter and the username part of the next bit to whatever your column is called in the csv.

 

Edit: Obviously you can expand this quite a bit but that should get you started. If you've got any questions then feel free to PM me or post here. If you've got some more details on what you'd like to do with the script then let us know, I'm sure some of us have probably done either the same thing or something similar and can help you out.

Edited by halbaradkenafin

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...