Avatar of Purti Bajaj
Purti Bajaj
 asked on

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!!!!
Active Directory

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon
oBdA

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.
Purti Bajaj

ASKER
Thanks for your quick response!!

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

Kindly help .
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Shaun Vermaak

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Purti Bajaj

ASKER
$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.
Shaun Vermaak

Please post your CSV
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Shaun Vermaak

Any feedback?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
oBdA

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.