Forum Discussion
Lovekesh Arora ( Office 365)
Nov 16, 2017Copper Contributor
Run the same Cmdlets for 100 different tenant
Hi Guys, Need your expertise for a power shell Script. I have around 100 tenants for which i want to run a same command and want to get the output in a CSV file. And i have Admin username and p...
Manidurai Mohanamariappan
Nov 17, 2017Iron Contributor
You can try this script
$path= "C:\csv\users.csv"
$csvs = Import-Csv $Path
$Allcompanyinfo = @()
foreach($values in $csvs )
{
$username=$values.username
$password= $values.password
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Connect-MsolService –Credential $cred
$companyifo = Get-MsolCompanyInformation
$Allcompanyinfo+= $companyifo
$companyifo =$null
}
$Allcompanyinfo | Export-csv "C:\csv\companyinfo.csv" -NoTypeInformation