Modifying description of multiple AD groups via powershell.

Hello,

I am Purti Bajaj , and i need one script which update my description for multiple groups in active directory.

I am importing csv file but even though i m getting "object not found error".

Below are the sample of script which i m using.


$file = Import-Csv C:\temp\group1.csv
foreach ($line in $file){
 
    set-adgroup '$($line.Groupname)' -Description '$($line.Description)'
}

Kindly look into this and do the needful.

Thanks in Advance!!!!
Purti BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You're using single quotes around the group name and description; this tells PS to not expand variables inside the string.
You need to use double quotes instead.
$file = Import-Csv C:\temp\group1.csv 
ForEach ($line in $file) { 
	Set-ADGroup "$($line.Groupname)" -Description "$($line.Description)"
}

Open in new window

That said, since you're only using the values from the csv, without adding anything to the string,, you can use the variables just as they are:
$file = Import-Csv C:\temp\group1.csv 
ForEach ($line in $file) { 
	Set-ADGroup "$($line.Groupname)" -Description "$($line.Description)"
}

Open in new window


And please use [code][]/code] tags (see the toolbar above the input field) when posting code.
0
Purti BajajAuthor Commented:
Thanks for your quick response!!

Even i m using double quote too, its not working.

Kindly help .
0
oBdACommented:
Copy and paste error with the second block, that should have been
$file = Import-Csv C:\temp\group1.csv 
ForEach ($line in $file) { 
	Set-ADGroup $line.Groupname -Description $line.Description
}

Open in new window


And since you're working in IT, you should know that "its not working" is not a kind of error description that can be used to start beginning troubleshoot.
What is the exact error message you're getting?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Shaun VermaakTechnical Specialist IVCommented:
The "object not found error" that you are getting might be because, as the command stands, you need to use Per-Windows 2000 group name.
In this example I have to use "Some Group 1" and not "Some Group 12"
SomeGroup.jpg
0
Purti BajajAuthor Commented:
$file = Import-Csv C:\temp\group1.csv 
ForEach ($line in $file) { 
	Set-ADGroup $line.Groupname -Description $line.Description
}

Open in new window


But i m getting below error:
Set-ADGroup : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
0
Shaun VermaakTechnical Specialist IVCommented:
Please post your CSV
0
oBdACommented:
Then your CSV has no header line, or the columns are named differently than "GroupName" and "Description".
0
Shaun VermaakTechnical Specialist IVCommented:
Any feedback?
0
oBdACommented:
The initial error was definitely that Set-ADGroup was searching for the literal string [b]$($line.Groupname)[/b].
The second error can only result from an incorrect csv.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.