Modifying description of multiple AD groups via powershell.

Purti Bajaj
Purti Bajaj used Ask the Experts™
on
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!!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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.

Author

Commented:
Thanks for your quick response!!

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

Kindly help .
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
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?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
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

Author

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.
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Please post your CSV
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Then your CSV has no header line, or the columns are named differently than "GroupName" and "Description".
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Any feedback?
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial