this is my csv file. i made a slight change in the .csf file. now im getting a message that says<\/p>\n<\/blockquote>\n<\/aside>\n
\nNeally: \nAlso possibly it can’t find it and you might have to query AD first.<\/p>\n<\/blockquote>\n
this is exactly what is happening, you have to either use the samaccountname, or query AD first.<\/p>","upvoteCount":0,"datePublished":"2019-06-25T15:41:39.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
the users are in another group called VDI_production_FI. so how do i point the location of the users which are currently in vdi_production_fi and have specified users transferred from that group to vdi_production. if there is another way i can do it without using the .csv file please advise. i greatly appreciate your assistance.<\/p>","upvoteCount":0,"datePublished":"2019-06-25T15:53:28.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/6","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nthe users are in another group called VDI_production_FI. so how do i point the location of the users which are currently in vdi_production_fi and have specified users transferred from that group to vdi_production. if there is another way i can do it without using the .csv file please advise. i greatly appreciate your assistance.<\/p>\n<\/blockquote>\n<\/aside>\n
You could do something like this:<\/p>\n
Get-ADGroupMember -Identity VDI_Production_FI | ForEach { Add-ADGroupMember -Identity VDI_Production -Members $_; Remove-ADGroupMember -Identity VDI_Production_FI -Members $_ }\n<\/code><\/pre>\nThis will find the users in the VDI_Production_FI, add them to VID_Production, and then remove them from VDI_Production_FI.<\/p>","upvoteCount":1,"datePublished":"2019-06-25T16:10:11.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/7","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"
Neally I tried running this command to quarry AD but im running to some dificulties.<\/p>\n
PS P:\\> Get-ADUser -Filter * -SearchBase \"OU=vdi_production_fi,ou=useraccounts,DV=nlacrc,DC=org\"\n\nGet-ADUser : The supplied distinguishedName must belong to one of the following partition(s): 'DC=nlacrc,DC=org , CN=Configuration,DC=nlacrc,DC=org , \nCN=Schema,CN=Configuration,DC=nlacrc,DC=org , DC=ForestDnsZones,DC=nlacrc,DC=org , DC=DomainDnsZones,DC=nlacrc,DC=org'.\nAt line:1 char:1\n+ Get-ADUser -Filter * -SearchBase \"OU=vdi_production_fi,ou=useraccount ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException\n + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser\n \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-06-25T16:10:34.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/8","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"will i be able to use a .csv file with the code that you gave me to move the users? the system admin wants me to move the users in small batches. he will be sending me the names of the users that are okay to move.<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:13:35.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/9","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nNeally I tried running this command to quarry AD but im running to some dificulties.<\/p>\n
PS P:\\> Get-ADUser -Filter * -SearchBase \"OU=vdi_production_fi,ou=useraccounts,DV=nlacrc,DC=org\"\n\nGet-ADUser : The supplied distinguishedName must belong to one of the following partition(s): 'DC=nlacrc,DC=org , CN=Configuration,DC=nlacrc,DC=org , \nCN=Schema,CN=Configuration,DC=nlacrc,DC=org , DC=ForestDnsZones,DC=nlacrc,DC=org , DC=DomainDnsZones,DC=nlacrc,DC=org'.\nAt line:1 char:1\n+ Get-ADUser -Filter * -SearchBase \"OU=vdi_production_fi,ou=useraccount ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException\n + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser\n \n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nIs VDI_Production_FI a group or an organizational unit?<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:14:32.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/10","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"
VDI_production_fi is a security group in AD<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:15:15.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/11","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nwill i be able to use a .csv file with the code that you gave me to move the users? the system admin wants me to move the users in small batches. he will be sending me the names of the users that are okay to move.<\/p>\n<\/blockquote>\n<\/aside>\n
No, the code that I posted does not use CSV, because you requested a method that does not require a CSV file.<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:15:22.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/12","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"
Neally i appreciate your patience.<\/p>\n
is there a way i can specify the names of the users that i’m assigned to move. kinda like “please move user \" username” from vdi_production_fi to vdi_production_ then remove username from vdi_production_fi\"<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:21:52.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/13","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nwill i be able to use a .csv file with the code that you gave me to move the users? the system admin wants me to move the users in small batches. he will be sending me the names of the users that are okay to move.<\/p>\n<\/blockquote>\n<\/aside>\n
If you need to use a CSV file, you should follow the advice that Neally gave you.<\/p>\n\n\n
<\/div>\n
Neally:<\/div>\n
\n\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nthis is my csv file. i made a slight change in the .csf file. now im getting a message that says<\/p>\n<\/blockquote>\n<\/aside>\n
\nNeally: \nAlso possibly it can’t find it and you might have to query AD first.<\/p>\n<\/blockquote>\n
this is exactly what is happening, you have to either use the samaccountname, or query AD first.<\/p>\n<\/blockquote>\n<\/aside>","upvoteCount":0,"datePublished":"2019-06-25T16:24:15.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/14","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nNeally i appreciate your patience.<\/p>\n
is there a way i can specify the names of the users that i’m assigned to move. kinda like “please move user \" username” from vdi_production_fi to vdi_production_ then remove username from vdi_production_fi\"<\/p>\n<\/blockquote>\n<\/aside>\n
Yes.<\/p>\n
$User = Get-ADUser <username>\nAdd-ADGroupMember -Identity VDI_Production -Members $User\nRemove-ADGroupMember -Identity VDI_Production_FI -Members $User\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-06-25T16:26:42.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/15","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"so I only need to enter the username in the first line correct?<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:34:50.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/16","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\nso I only need to enter the username in the first line correct?<\/p>\n<\/blockquote>\n<\/aside>\n
Correct.<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:50:19.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/17","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"
$User = Get-ADUser <rick james>\nAdd-ADGroupMember -Identity VDI_Production -Members $User\nRemove-ADGroupMember -Identity VDI_Production_FI -Members $User\n<\/code><\/pre>\nLike so?<\/p>","upvoteCount":0,"datePublished":"2019-06-25T16:52:02.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/18","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-f8scc:<\/div>\n
\n$User = Get-ADUser <rick james>\nAdd-ADGroupMember -Identity VDI_Production -Members $User\nRemove-ADGroupMember -Identity VDI_Production_FI -Members $User\n<\/code><\/pre>\nLike so?<\/p>\n<\/blockquote>\n<\/aside>\n
Not quite.<\/p>\n
\n\nI used angle bracket <> to represent information that you need to enter, because Powershell documentation follows that formatting convention. The angle brackets are not part of the syntax.<\/p>\n<\/li>\n
\nYou need to use samAccountName, objectGUID, or distinguishedName for Get-ADUser. It does not accept displayName, because that is not a unique way to identify an account.<\/p>\n<\/li>\n<\/ol>\n
$User = Get-ADUser samAccountName\nAdd-ADGroupMember -Identity VDI_Production -Members $User\nRemove-ADGroupMember -Identity VDI_Production_FI -Members $User\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-06-25T17:02:36.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/19","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"will it work if i enter multiple user names in line one?. if so will it work if i separate the multiple names by quotation marks \" \".<\/p>","upvoteCount":0,"datePublished":"2019-06-25T19:27:01.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-correcting-powershell-code/718068/20","author":{"@type":"Person","name":"spiceuser-f8scc","url":"https://community.spiceworks.com/u/spiceuser-f8scc"}}]}}
import-csv "C:\temp\testgroup.csv" | ForEach-Object {add-ADGroupMember -Identity $_.groupname -Members $_.username}
Hi Guys
I found this code and want to modify it to transfer users from one group to another using a .csv file.
so i made a .csv file and entered the information below. when i run the code i get a message
Add-ADGroupMember : Cannot validate argument on parameter ‘Members’. The argument is null or empty. Provide an argument that is not null or empty, and then try the
command again.
At line:1 char:104
… bject {add-ADGroupMember -Identity $.groupname -Members $ .username}
CategoryInfo : InvalidData: ( [Add-ADGroupMember], ParameterBindingValidationException
FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
members,groupname
Frank Mendoza,VDI_production
4 Spice ups
Neally
(Neally)
June 25, 2019, 3:12pm
2
What does your CSV file look like? Does it have a ‘groupname’ and ‘username’ column?
Neally
(Neally)
June 25, 2019, 3:15pm
3
yeah if that is your CSV you have to adjust your code to
$_.members
Also possibly it can’t find it and you might have to query AD first.
1 Spice up
this is my csv file. i made a slight change in the .csf file. now im getting a message that says
add-ADGroupMember : Cannot find an object with identity: ‘Frank Mendoza’ under: ‘DC=nlacrc,DC=org’.
At line:1 char:54
… ach-Object {add-ADGroupMember -Identity $.groupname -Members $ .user …
CategoryInfo : ObjectNotFound: (Frank Mendoza:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
testgroup.txt (50 Bytes)
Neally
(Neally)
June 25, 2019, 3:41pm
5
Neally:
Also possibly it can’t find it and you might have to query AD first.
this is exactly what is happening, you have to either use the samaccountname, or query AD first.
the users are in another group called VDI_production_FI. so how do i point the location of the users which are currently in vdi_production_fi and have specified users transferred from that group to vdi_production. if there is another way i can do it without using the .csv file please advise. i greatly appreciate your assistance.
Evan7191
(Evan7191)
June 25, 2019, 4:10pm
7
You could do something like this:
Get-ADGroupMember -Identity VDI_Production_FI | ForEach { Add-ADGroupMember -Identity VDI_Production -Members $_; Remove-ADGroupMember -Identity VDI_Production_FI -Members $_ }
This will find the users in the VDI_Production_FI, add them to VID_Production, and then remove them from VDI_Production_FI.
1 Spice up
Neally I tried running this command to quarry AD but im running to some dificulties.
PS P:\> Get-ADUser -Filter * -SearchBase "OU=vdi_production_fi,ou=useraccounts,DV=nlacrc,DC=org"
Get-ADUser : The supplied distinguishedName must belong to one of the following partition(s): 'DC=nlacrc,DC=org , CN=Configuration,DC=nlacrc,DC=org ,
CN=Schema,CN=Configuration,DC=nlacrc,DC=org , DC=ForestDnsZones,DC=nlacrc,DC=org , DC=DomainDnsZones,DC=nlacrc,DC=org'.
At line:1 char:1
+ Get-ADUser -Filter * -SearchBase "OU=vdi_production_fi,ou=useraccount ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
will i be able to use a .csv file with the code that you gave me to move the users? the system admin wants me to move the users in small batches. he will be sending me the names of the users that are okay to move.
Evan7191
(Evan7191)
June 25, 2019, 4:14pm
10
spiceuser-f8scc:
Neally I tried running this command to quarry AD but im running to some dificulties.
PS P:\> Get-ADUser -Filter * -SearchBase "OU=vdi_production_fi,ou=useraccounts,DV=nlacrc,DC=org"
Get-ADUser : The supplied distinguishedName must belong to one of the following partition(s): 'DC=nlacrc,DC=org , CN=Configuration,DC=nlacrc,DC=org ,
CN=Schema,CN=Configuration,DC=nlacrc,DC=org , DC=ForestDnsZones,DC=nlacrc,DC=org , DC=DomainDnsZones,DC=nlacrc,DC=org'.
At line:1 char:1
+ Get-ADUser -Filter * -SearchBase "OU=vdi_production_fi,ou=useraccount ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Is VDI_Production_FI a group or an organizational unit?
VDI_production_fi is a security group in AD
Evan7191
(Evan7191)
June 25, 2019, 4:15pm
12
No, the code that I posted does not use CSV, because you requested a method that does not require a CSV file.
Neally i appreciate your patience.
is there a way i can specify the names of the users that i’m assigned to move. kinda like “please move user " username” from vdi_production_fi to vdi_production_ then remove username from vdi_production_fi"
Evan7191
(Evan7191)
June 25, 2019, 4:24pm
14
If you need to use a CSV file, you should follow the advice that Neally gave you.
Evan7191
(Evan7191)
June 25, 2019, 4:26pm
15
spiceuser-f8scc:
Neally i appreciate your patience.
is there a way i can specify the names of the users that i’m assigned to move. kinda like “please move user " username” from vdi_production_fi to vdi_production_ then remove username from vdi_production_fi"
Yes.
$User = Get-ADUser <username>
Add-ADGroupMember -Identity VDI_Production -Members $User
Remove-ADGroupMember -Identity VDI_Production_FI -Members $User
so I only need to enter the username in the first line correct?
Evan7191
(Evan7191)
June 25, 2019, 4:50pm
17
$User = Get-ADUser <rick james>
Add-ADGroupMember -Identity VDI_Production -Members $User
Remove-ADGroupMember -Identity VDI_Production_FI -Members $User
Like so?
Evan7191
(Evan7191)
June 25, 2019, 5:02pm
19
Not quite.
I used angle bracket <> to represent information that you need to enter, because Powershell documentation follows that formatting convention. The angle brackets are not part of the syntax.
You need to use samAccountName, objectGUID, or distinguishedName for Get-ADUser. It does not accept displayName, because that is not a unique way to identify an account.
$User = Get-ADUser samAccountName
Add-ADGroupMember -Identity VDI_Production -Members $User
Remove-ADGroupMember -Identity VDI_Production_FI -Members $User
will it work if i enter multiple user names in line one?. if so will it work if i separate the multiple names by quotation marks " ".