Wednesday, March 9, 2022

Add all users except guest account as a Sharepoint online site viewer access

 

$SiteURL = "https://test.sharepoint.com/sites/team"
Connect-PnPOnline -Url $SiteURL -UseWebLogin
$Group = Get-PnPGroup -AssociatedVisitorGroup
$User = "Everyone except external users"
Add-PnPGroupMember -LoginName $User -Identity $Group

Monday, September 6, 2021

Create Headerless search result plage



#1)Create a page with normal layout in SharePoint
Connect-PnPOnline https://shared.sharepoint.com/sites/IT
Get-PnPClientSidePage -Identity results
Set-PnPClientSidePage -Identity results -LayoutType HeaderlessSearchResults

Saturday, September 4, 2021

Get the office 365 Compliance report

Install-Module -Name ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement

$Credential = Get-Credential #-credential  used to connect Azure AD 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking -AllowClobber

$StartDate=(((Get-Date).AddDays(-30))).Date  # Report for last 30 days 
$EndDate=Get-Date
$Operation="UserLoggedIn" #Login details
$Results=Search-UnifiedAuditLog  -UserIds 'Abc@abc.com' -StartDate $StartDate -EndDate $EndDate -operations $Operation -ResultSize 1 |select UserIds , CreationDate 
$Results

Wednesday, May 19, 2021

Finding data in CSV file from other CSV file

#http://hilite.me/
#Create folder 
$Path = "C:\Temp\PowerShell - Enterprise\PSTN\90 days" # Location of file to be saved
$PSTNLicenseUserSource = Import-Csv -Path "$($path)\PSTNLicenseUserDomesticlCalling120.csv" # CSV file having list of user with license 
$30DaysTeamsLogs = Import-Csv -Path "$($path)\TeamsLogs.csv" # CSV file downloaded from Teams logs for last 30 days 

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


    ForEach ($PSTNLicenseUser in $PSTNLicenseUserSource)
    {

        $30DaysTeamLogsSingleUserData = $30DaysTeamsLogs |  where {$_.UPN -eq $PSTNLicenseUser."User principal name" } 
        
        $DataMatchInTeamsLogs =  $30DaysTeamLogsSingleUserData | Select-Object -first 1

        If($DataMatchInTeamsLogs) # If record gets found 
        {
        
            
            #Write-Host $DataMatchInTeamsLogs.UPN -ForegroundColor green
            #Add-Content $LogFileName -Value ([string]::Concat($($DataMatchInTeamsLogs.UPN) +","+ $($DataMatchInTeamsLogs."Duration Seconds") +","+ "Yes"))

        
        }
        else #Unable to find the record
        {

        Write-Host $PSTNLicenseUser."User principal name" -ForegroundColor white
        Add-Content $LogFileName -Value ([string]::Concat($($PSTNLicenseUser."User principal name") +","+ "0" +","+ "No"))
        }
    }

Friday, March 26, 2021

Azure AD service principal enterprise app disable

try 
    { 

        $var = Get-AzureADTenantDetail 
    } 

   catch [Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException] 
    { 
        Write-Host "You're not connected."; 
        Write-Host -ForegroundColor Red " *** Error With Azure AD Connection **" 
              
       
        $Credential = Get-Credential #-credential  used to connect Azure AD 
        Connect-AzureAD -Credential $Credential

    }

$Path = "C:\Temp\PowerShell - Enterprise\Process" # Location of file to be saved

Get-AzureADServicePrincipal -All $true | Export-Csv -Path ""$($path)\Processes.csv"" -NoTypeInformation # Pull the list of all enterprise apps in the Tenant
$AppListSource = Import-Csv -Path "$($path)\Processes.csv" # Read the CSV file having list of all Apps name , 


$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 Display Name"+","+ "Oject ID" +","+ "App ID"+","+ "Application Access Dates"+","+ "UserPrincipalName"))


    ForEach ($AppNameSource in $AppListSource)
    {

        
        
        $varAppId = $AppNameSource.AppId
        
        $LoginDetails  = Get-AzureAdAuditSigninLogs -top 1 -filter "AppId eq '$varAppId'" | select CreatedDateTime, userprincipalname 

             
            
           Write-Host $AppNameSource.DisplayName "--"   $LoginDetails.userprincipalname  -ForegroundColor white
           Add-Content $LogFileName -Value ([string]::Concat($($AppNameSource.DisplayName) +","+ $($AppNameSource.ObjectId) +","+ $($AppNameSource.AppId)+","+ $LoginDetails.CreatedDateTime+","+ $LoginDetails.userprincipalname))

           $value = $LoginDetails.userprincipalname
           
                if ( $value -ne $null )
            {
                

                 $appId = $AppNameSource.AppId

                # Check if a service principal already exists for the app
                $servicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq '$appId'"
                if ($servicePrincipal) {
                # Service principal exists already, disable it
                  Set-AzureADServicePrincipal -ObjectId $servicePrincipal.ObjectId -AccountEnabled $false
                } 

            }

        
       
    }


    

   

Friday, March 19, 2021

Last login details report from the Azure AD enterprise apps

 #Connect with Azure AD UserPrincipalName 

    try 
    { 

        $var = Get-AzureADTenantDetail 
    } 

   catch [Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException] 
    { 
        Write-Host "You're not connected."; 
        Write-Host -ForegroundColor Red " *** Error With Azure AD Connection **" 
              
       
        $Credential = Get-Credential #-credential  used to connect Azure AD 
        Connect-AzureAD -Credential $Credential

    }

$Path = "C:\Temp\PowerShell - Enterprise\Process" # Location of file to be saved

Get-AzureADServicePrincipal -All $true | Export-Csv -Path ""$($path)\Processes.csv"" -NoTypeInformation # Pull the list of all enterprise apps in the Tenant
$AppListSource = Import-Csv -Path "$($path)\Processes.csv" # Read the CSV file having list of all Apps name , 


$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 Display Name"+","+ "Oject ID" +","+ "App ID"+","+ "Application Access Dates"+","+ "UserPrincipalName"))




    ForEach ($AppNameSource in $AppListSource)
    {

        
        
        $varAppId = $AppNameSource.AppId
        
        $LoginDetails  = Get-AzureAdAuditSigninLogs -top 1 -filter "AppId eq '$varAppId'" | select CreatedDateTime, userprincipalname 

             
            
           Write-Host $AppNameSource.DisplayName "--"   $LoginDetails.userprincipalname  -ForegroundColor white
           Add-Content $LogFileName -Value ([string]::Concat($($AppNameSource.DisplayName) +","+ $($AppNameSource.ObjectId) +","+ $($AppNameSource.AppId)+","+ $LoginDetails.CreatedDateTime+","+ $LoginDetails.userprincipalname))

        
       
    }

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"))
        }
    }

HTML

Script:

JS