powershell - empty list of group's members - powershell

i'm trying to export to csv file list (or table but for now it doesn't matter) with the members of a group .
after many searches and i tried :
Get-ADGroupMember -Identity **genericGroupName** -recursive | select name | Export-csv output.csv -NoTypeInformation
i also tried to change some things in this command- remove the -recursive .
i tried to find the problem in the command and remove the -Export-csv output.csv -NoTypeInformation
but it showed nothing (in nothing i mean - show my command and then nothing)
my problem is that i got the output.csv , but it is empty.
if it matters :
the genericGroupName is actually :
$group = (Get-ADUser -Identity userName -properties MemberOf | select memberOf).memberOf
and
genericGroupName --> $group[0]
this command works well.

I fixed this problem (accidentally) by closing the powershell ISE and then open it.
I am still don't know what was the problem but somehow it fixed by closing the powershell

Related

Powershell: what does "Supply values for the following parameters / Input Object" mean?

I am currently trying to export a list of AD-Users per every AD-Group, which starts with "AD-AllowMailbox*"
Since there are more than 200+ AD-Groups like this (AD-AllowMailbox-Parking, AD-AllowMailbox-Office..) I prefer to do this with a single script.
The powershell code I am using is:
Get-ADGroup -Filter '(Name -like "AD-AllowMailbox-*")' |
ForEach-Object {Get-ADGroupMember -Recursive -Identity $_} |
Select-Object -ExpandProperty 'Name' |
Sort-Object -Unique
Export-Csv -NoTypeInformation -Path C:\Users\Admin\mailbox.csv
The script runs. However, I get the following message in powershell:
cmdlet Export-Csv at command pipeline position 1
Supply values for the following parameters:
InputObject:
What does this mean and why does it pop up? No matter what value I insert as input, I get an empty .csv.
Am I missing something in the script?

Powershell simple script

I have a simple script that is made to search the members of a group introduced as a parameter, and it works properly:
$param1=$args[0]
Get-ADGroupMember "$param1" | ft name,objectclass,samaccountname
But when I try to run this other script (very similar funtionality), it doesn't show anything,, just blank:
$param1=$args[0]
Get-ADUser -Filter 'Name -like "*$param1*"' -Properties LastLogonDate,PasswordLastSet | ft Name,SamAccountName,LastLogonDate,PasswordLastSet
Someone could help me, what am I doing wrong?
PD: When I run the second command manually, replacing $param1 with a letter, it works as intended.
---NEWS---
I have tried this variation of the second script and idk why but it works:
Get-ADUser -Identity "$args" -Properties LastLogonDate,PasswordLastSet | ft Name,SamAccountName,LastLogonDate,PasswordLastSet
May it be, that the option "-Filter 'Name -like "$args"'" it's what is causing all the trouble?
It's very strange because, the second script doesn't show an error, it just doesn't show nothing and goes to the next prompt line. (I have already tried to replace the $param1 with $args like in the last example and it's the same output, nothing)
Thanks in advice :))
Alex, Try this instead. Get-ADUser -Filter "Name -like '*$($param1)*'" -Properties LastLogonDate,PasswordLastSet | ft Name,SamAccountName,LastLogonDate,PasswordLastSet

How to get the get-ADPrincipalGroupMembership for all users in a txt or csv file and put into a txt file for each user?

I am trying to get a file with the group-memberships for every user that is specified in a txt/csv file.
so this is what i had before:
Get-ADPrincipalGroupMembership -Identity $user -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "C:\temp\$user.txt"
this work fine for getting the groups from 1 singel user, but now i have to do this for 100+ users.
And instead of doing it one by one i am looking for a way to automate it.
so i got myself a .csv export of all the users i want this done for.
and started trying.
what i came up with so far:
$users = Get-Content "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $users -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$users.txt"}
This cleary doesnt work.
I have tried a couple of other things with the foreach command but nothing did the trick.
I have the feeling i am not on the right path to get my result.
Maby somebody has done this before and can help me get on the right path.
i'm not new to powershell but i'm far from an expert, most of the time i use it for basic singel commands or edit some great scripts i find.
sadly for this i haven't found any yet.
with kind regards
Roland
Don't assign back to a variable
Import the CSV
No filter after select
Pretiffy your -like
Use $_ as pipeline variable
Use subexpression operator for string+variable concatenation
Import-Csv "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $_.users -Server $_.DC | Where-Object {$_.name -like 'GUSR_*'} | Select -Expand Name | Out-String | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$($_.users).txt"}

Opening the output file automatically

I have a script that creates a csv file which I then go open to get the information I am looking for. Is there a way to add to the script so that the file opens immediately as well as saves in the specified location?
Get-ADComputer -Filter { Enabled -eq $true } -Properties Name -SearchBase
"DC=REMOVED,DC=com" |
Select Name |
? {$_. Name -like "X*" } |
Export-Csv "C:\scripts\Computers.csv"
Add this quick snippet to the end of your code:
Invoke-Item "C:\scripts\Computers.csv"
If you have Excel automatically configured to support/open .csv files, it should open automatically.
EDIT: Note that this isn't available in Powershell 2.0 - only 3.0+

Updating Phonenumbers in AD via csv with Powershell

Please guys, help me out here.
I have created a file with the following command:
Get-ADUser -Filter * -Properties samAccountName,DistinguishedName,telephoneNumber | select-object samAccountName,DistinguishedName,telephonenumber,address,city | Export-Csv C:\Shares\TESTSHARE\new3.csv -notypeinformation -delimiter ";" -Encoding utf8;
This works like a charm, but for the love of god, I cannot manage to import it again, all I wanna do is change the phonenumbers in the excel sheet, and insert the altered file into the AD.
Basically this has robbed me three days worth of time already, and my client is becoming edgy..
EDIT:
I tried to run the script which was posted by Ansgar Wiechers but unfortunately I got a few error messages.
Use the complementary cmdlets in reverse order:
$csv = 'C:\Shares\TESTSHARE\modified3.csv'
Import-Csv $csv -Delimiter ';' -Encoding UTF8 | % {
Get-ADUser -Identity $_.samAccountName |
Set-ADUser -OfficePhone $_.telephonenumber
}
Edit: Your error messages suggest that you try to assign empty telephone numbers. Verify that by adding the following line before Get-ADuser:
Write-Output "{0} [{1}]" -f $_.samAccountName, $_.telephonenumber