Trying to determine managedby attribute for specific distributionlist - powershell

I've a text file with a list of distribution groups that I'm trying to get managedby attribute. I tried running different commands but seems to be a syntax issue ( fairly new to PowerShell) because I'm able to retrieve the attribute managedby for single distribution group. When I'm formatting and exporting the result to csv file all I get is a bunch of numbers. I'm on powershell exchange server 2008.

Starting with a flat text file named groups.txt:
Employees#company.com
Executives#company.com
Suggested Solution:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
$grouplist | Export-Csv -Path results.csv -NoTypeInformation
Gives results like:
"PrimarySmtpAddress","ManagedBy"
"Employees#company.com","admin"
"Executives#company.com","admin"
Reproducing the "bunch of numbers" issue:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
Export-Csv -InputObject $grouplist -Path results2.csv -NoTypeInformation
Resulted in:
"Count","Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized"
"2","2","2","1","System.Object[]","False","True","False"
Environment: Exchange 2013, Powershell 5.0, Windows 10 Tech Preview 3

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?

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"}

Powershell split items into text file into multiple variables

I am trying to run a software script against my servers, to see exactly what software is installed and what version. I have the list of the servers stored in a text file "SystemList.txt" that is formatted like you see below.
SERVER001
SERVER002
SERVER003
SERVER004
I need to pull the server names out of the file and use them in my csv that I need to look like this:
Here is the code:
$computers = Get-Content -path
D:\Users\stephen.lyons.sa\Documents\SystemList\SystemList.txt
Foreach($computer in $computers)
{
$computer
$env:COMPUTERNAME
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
|Select-Object Displayname, DisplayVersion, Publisher, InstallDate | Out-
file \\txusocts002\d$\APSO\Steve\Test\$env:COMPUTERNAME.csv
}
Perhaps I am missing something, but would this meet your CSV file need?
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object -Property DisplayName,DisplayVersion,Publisher,InstallDate |
Export-Csv -Path my.csv

Outputing contents to CSV with Powershell

I use this site alot while learning Powershell. Its been a great help so far!
Here is my issue:
I am trying to write a script that will take workstation names, pull the workstation description from WMI and output both the workstation name and description found into a new .csv file.
Here is what I have so far:
Get-Content -Path "workstation_names.csv" | Select-Object Workstations |
Foreach-Object { Get-WmiObject -Class Win32_OperatingSystem -ComputerName $workstations | Select Workstations, Description | Export-CSV -Path "results.csv" -NoTypeInformation }
The workstation_names.csv has a column named "Workstations" and under it each cell has a single workstation name in it. Currently my script will create an output file that will have two columns in it. One called "Workstations" and the other called "Description". The Workstation column is empty, and the Description column only has the results for the first workstation description in it (even though I have 10 workstation names listed in the workstation_names.csv file).
I am sitting here scratching my head with my n00bish knowledge of Powershell. I know I PROBABLY need to so something with the array that is created from the first .csv file but I am not sure how to code what I need. Any help??
Probably something like this should do the trick:
$inFile = "workstation_names.csv"
$results = #()
Import-CSV -path $inFile -header Workstations |
% {$results += Get-WmiObject -Class Win32_OperatingSystem `
-ComputerName $_.Workstations | Select PSComputerName, Description}
$results | Export-Csv -Path "results.csv" -NoTypeInformation
So to elaborate on this, you aren't really importing the CSV, you are importing the raw text file, which is confusing, since I don't really understand how anything works for you in that case. Here the script will create an array to store the results, import file as CSV, loop through the valuables and output results to the CSV.
4c74356b41's script will fail for several reasons
It's -header not -headers
there is a typo %_ instead of $_
select Workstations won't work as that's no property of gwmi
This only slightly reworked script should do.
$inFile = "workstation_names.csv"
$results = #()
Import-CSV -path $inFile -header Workstations |
% {$results += Get-WmiObject -Class Win32_OperatingSystem `
-ComputerName $_.Workstations | Select PSComputerName, Description}
$results | Export-Csv -Path "results.csv" -NoTypeInformation
To see which properties are available see the following output
GWmi -Class Win32_OperatingSystem -ComputerName localhost|gm|out-gridview

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