We help IT Professionals succeed at work.

Modifying description of multiple AD groups via powershell.

Purti Bajaj
Purti Bajaj asked
on
66 Views
Last Modified: 2017-05-02
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

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable 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 .
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

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 VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
Please post your CSV
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
Any feedback?
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable 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.