K B
asked on
PowerShell: Importing a CSV to gather information with Get-MsolUser -- to be used in ForEach
$U = import-csv C:\scripts\test.csv
$users | % {Get-MsolUser $_
foreach ($user in $users) {
The error I get is: Get-MsolUser : A positional parameter cannot be found that accepts argument '$null'.
Thank you.
ASKER
Thanks for reply.
I need a variable ($users) to contain all the results from the Get-MsolUser... the CSVs would contain all the upns only.. i need all the data in the get-msoluser to end up in $users ... then foreach
I need a variable ($users) to contain all the results from the Get-MsolUser... the CSVs would contain all the upns only.. i need all the data in the get-msoluser to end up in $users ... then foreach
Or if you want to use a foreach loop
foreach ($user in (Import-Csv C:\scripts\test.csv)) {
Set-Whatever $user.Name
}
In that example the .csv file would have a column entitled 'Name'
$users = Import-Csv C:\scripts\test.csv
foreach ($user in $users) {
Set-Whatever $user.Name
}
ASKER
$users shouldn't be the csv
I want to pass $csv (for example) to get-msoluser AND that should all be stored in $users....then loop
I want to pass $csv (for example) to get-msoluser AND that should all be stored in $users....then loop
If I'm understanding you correctly you should be able to skip the .csv file:
Import-Module msonline
$users = Get-MsolUser
foreach ($user in $users) {
Set-Whatever $user.UserPrincipalName
}
ASKER
I cannot skip the CSV file
I can see a use for either a .csv file or a variable containing a list of users but not both. What is the ultimate goal of this script?
ASKER
i have a list of UPNs
that $csv would give me $csv.userprincipalname's.. ..
I need to take the list of $csv and get $users (which would contain all the properties of get-msoluser - for the list only)
there are 23,000 MsolUsers
the list has 500 MsolUsers
so you see why it has to be a csv
that $csv would give me $csv.userprincipalname's..
I need to take the list of $csv and get $users (which would contain all the properties of get-msoluser - for the list only)
there are 23,000 MsolUsers
the list has 500 MsolUsers
so you see why it has to be a csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
You have to specify the .csv column name after using $_