Link to home
Start Free TrialLog in
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!!!!
Avatar of oBdA
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.
Avatar of Purti Bajaj

ASKER

Thanks for your quick response!!

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

Kindly help .
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"
User generated image
$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.
Please post your CSV
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any feedback?
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.