Friday, March 19, 2021

Compare two CSV file Data

$Path = "C:\Temp\PowerShell - Enterprise\Final" # Location of file to be saved
$AppListSource = Import-Csv -Path "$($path)\AppList.csv" # CSV file having list of all Apps name ,  "Apps to review" tab
$30DaysAppLogs = Import-Csv -Path "$($path)\Logs.csv" # CSV file downloaded from Azure Apps logs for last 30 days 

$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
$LogFileName=([string]::Concat("$($path)\Apps_Report " , $Datetime ,".csv"))
New-Item  $LogFileName  -ItemType file
Add-Content $LogFileName -Value ([string]::Concat("Application Name"+","+ "Oject ID" +","+ "Accessed in 30 days Yes/No"))


    ForEach ($AppNameSource in $AppListSource)
    {

        $TempData = $30DaysAppLogs |  where {$_.Target1DisplayName -eq $AppNameSource.Target1DisplayName } 
        
        $DataMatch =  $TempData | Select-Object -first 1

        If($DataMatch)
        {
        
            
            Write-Host $DataMatch.Target1DisplayName -ForegroundColor white
            Add-Content $LogFileName -Value ([string]::Concat($($DataMatch.Target1DisplayName) +","+ $($DataMatch.Target1ObjectId) +","+ "Yes"))

        
        }
        else
        {

        Write-Host $DataMatch.Target1DisplayName -ForegroundColor white
        Add-Content $LogFileName -Value ([string]::Concat($($AppNameSource.Target1DisplayName) +","+ $($AppNameSource.Target1ObjectId) +","+ "No"))
        }
    }

No comments:

Post a Comment

HTML

Script:

JS