Murali Kris

Murali Kris

  • 1.5k
  • 254
  • 48k

How to bind values in to csv from Catch method

Dec 6 2021 1:47 PM

Hi Team,

I would like to create a CSV file for active users and inactive users. but I can create CSV file with only active users but not In-Active users.

$Output=foreach($sca in $scaColl)
{

    if($sca.Email -ne "")
    {
           try{
           $ActiveUser = Get-AzureADUser -ObjectId $sca.Email | Select-Object -Property DisplayName
           Write-Host $ActiveUser.DisplayName;
           
           New-Object -TypeName PSObject -Property @{
           Title = $ActiveUser.DisplayName;
           } | Select-Object Title
           }
           catch
           {
           New-Object -TypeName PSObject -Property @{
           InActive = $ActiveUser.DisplayName;
           } | Select-Object InActive
           
           Write-Host "Invalid User"+ $ActiveUser.DisplayName
           }       
    }
}
$Output | Export-Csv -Path D:\CSV\myVar.csv -NoTypeInformation

From the Try method, i can log with active users, but from the catch method, i can not create another column to add in-active users 

cany any one can assist me how to bind properly with above code.


Answers (2)