Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

run a powershell command using csv as an input

$
0
0

I am trying to run a powershell Office365 command "(Get-MsolUser -UserPrincipalName $test).Licenses.ServiceStatus" from a csv input.

My scripts looks like

$test = Import-Csv -Path "C:\temp\test.csv"

ForEach ($tests in $test)
{

(Get-MsolUser -UserPrincipalName $test).Licenses.ServiceStatus

}

The command runs fine if i put a user principle name instead of $test "(Get-MsolUser -UserPrincipalName Test@test.com).Licenses.ServiceStatus"

Could you please advise how can i run this command using csv input

Error that i get is

PS C:\WINDOWS\system32> (Get-MsolUser -UserPrincipalName $test).Licenses
Get-MsolUser : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'UserPrincipalName'.
Specified method is not supported.
At line:1 char:34
+ (Get-MsolUser -UserPrincipalName $test).Licenses
+                                  ~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-MsolUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Online.Administration.Automation.GetUser


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>