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

MFA Report

$loginURL = "https://login.microsoftonline.com"
$resource = "https://graph.microsoft.com"
$ClientSecret="qA-.-tt1A3rlu_4pe"
$ClientID="6301d5-e-45-6b4675a9a" # App id
$TenantName="test.onmicrosoft.com"
 
#Repeating Function to get an Access Token based on the parameters:
function RefreshToken($loginURL,$ClientID,$clientSecret,$tenantName)
{
$body = @{grant_type="client_credentials";client_id=$ClientID;client_secret=$ClientSecret;scope="https://graph.microsoft.com/.default"}
$oauthResponse = Invoke-RestMethod -Method POST -Uri $loginURL/$TenantName/oauth2/v2.0/token -Body $body
return $oauthResponse
}


 
#BUILD THE ACCESS TOKEN
$oauth=RefreshToken -loginURL $loginURL -resource $resource -ClientID $ClientID -clientSecret $ClientSecret -tenantName $TenantName
$Identity = $oauth.access_token
#$ClientSecret1 = "qA-.-tDjp6n5Wc9d84~tmset1A3rlu_4pe"
#$ClientSecret = ConvertTo-SecureString -String $ClientSecret1 -AsPlainText -Force

#$Token = Get-MsalToken -clientID $ClientID -tenantID $tenantId -Scope 'https://graph.microsoft.com/Policy.Read.All' -RedirectUri "https://login.microsoftonline.com/common/oauth2/nativeclient" -clientsecret $ClientSecret
#$Identity = $Token.AccessToken


$headerParams = @{'Authorization'="$($oauth.token_type) $($Identity)"}
$CAPolicies = "https://graph.microsoft.com/beta/conditionalAccess/policies"
#$CAPolicies = "https://graph.microsoft.com/beta/conditionalAccess/policies/06108f32-1950-4342-ae8f-968121a366d4"


$apirequest = (Invoke-WebRequest -Headers $headerParams -Uri $CAPolicies -Method GET)
$Logs = @()

foreach ($event in ($apirequest.Content | ConvertFrom-Json| select -ExpandProperty value))
{ 

$Log = New-Object System.Object
$Log | Add-Member -MemberType NoteProperty -Name "Policy ID" -Value $event.id
$Log | Add-Member -MemberType NoteProperty -Name "Policy Name" -Value $event.displayName
$Log | Add-Member -MemberType NoteProperty -Name  "Policy State" -value $event.state
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Last Updated Time" -value $event.modifiedDateTime
$Log | Add-Member -MemberType NoteProperty -Name "Policy Session Controls App Enforced Restrictions" -Value $event.sessionControls.applicationEnforcedRestrictions
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Session - CA App Control" -value $event.sessionControls.cloudAppSecurity
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Session - Sign in Frequency" -value $event.sessionControls.signInFrequency
$IncludedUsers = $event.conditions.users.includeUsers -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Included Users" -Value $IncludedUsers
$ExcludedUsers = $event.conditions.users.excludeUsers -join "; "

$Log | Add-Member -MemberType NoteProperty -Name "Policy Excluded Users" -Value $ExcludedUsers 




$IncludedGroups = $event.conditions.users.includeGroups -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Included Groups" -Value $IncludedGroups
$ExcludedGroups = $event.conditions.users.excludeGroups -join "; "

$Log | Add-Member -MemberType NoteProperty -Name "Policy Excluded Groups" -Value $ExcludedGroups # 


$IncludedRoles = $event.conditions.users.includeRoles -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Included Roles" -Value $IncludedRoles
$ExcludedRoles = $event.conditions.users.excludeRoles -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Excluded Roles" -Value $ExcludedRoles
$IncludedApps = $event.conditions.applications.includeApplications -join "; "

$Log | Add-Member -MemberType NoteProperty -Name  "Policy Included Applications" -value $IncludedApps
$ExcludedApps = $event.conditions.applications.excludeApplications -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Excluded Applications" -value $ExcludedApps
$IncludedUserActions = $event.conditions.applications.includeUserActions -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy User Actions" -value $IncludedUserActions
$ClientTypes = $event.conditions.clientAppTypes -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - Client Apps " -value $ClientTypes
$IncludedDevices = $event.conditions.devices.includeDeviceStates -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Conditions - Included Device States" -Value $IncludedDevices
$ExcludedDevices = $event.conditions.devices.excludeDeviceStates -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Conditions - Excluded Device States" -Value $ExcludedDevices
$IncludedLocations = $event.conditions.locations.includeLocations -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - Included Locations" -value $IncludedLocations
$ExcludedLocations = $event.conditions.locations.excludeLocations -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - Excluded Locations" -value $ExcludedLocations
$IncludedPlatforms = $event.conditions.platforms.includePlatforms -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - Included Device Platforms" -value $IncludedPlatforms
$ExcludedPlatforms = $event.conditions.platforms.excludePlatforms -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - Excluded Device Platforms" -value $ExcludedPlatforms
$SignInRiskLevels = $event.conditions.signInRiskLevels -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Conditions - SignInRiskLevels" -Value $RiskLevels
$UserRiskLevels = $event.conditions.userRiskLevels -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Conditions - UserRiskLevels" -value $UserRiskLevels
$BuildInControls = $event.grantControls.builtInControls -join "; "
$Log | Add-Member -MemberType NoteProperty -Name "Policy Controls" -Value $BuildInControls
$AuthFactors = $event.grantControls.customAuthenticationFactors -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Auth Factors" -value $AuthFactors
$TermsOfUse = $event.grantControls.termsOfUse -join "; "
$Log | Add-Member -MemberType NoteProperty -Name  "Policy Terms Of Use" -value $TermsOfUse
$Logs += $Log

}


Write-host "Add the Path you'd like us to export the CSV file to, in the format of <c: sers="">\Desktop\Users.csv&gt;" -ForegroundColor white -BackgroundColor Black

$Logs | Export-CSV  "C:\Temp\MFA Report\Results.csv" -NoTypeInformation -Encoding UTF8
</c:>

Thursday, March 18, 2021

Get the list of all Azure AD enterprise application list

Connect-AzureAD
Get-AzureADServicePrincipal -All $true
Get-AzureADServicePrincipal -All $true | Export-Csv -Path "C:\Temp\PowerShell - Enterprise\Processes.csv" -NoTypeInformation

Wednesday, February 17, 2021

Check CsTeamsMeetingPolicy

$adminUPN="ABC@Test.onMicrosoft.com"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
$sfbSession = New-CsOnlineSession -Credential $userCredential
Import-PSSession $sfbSession
Get-CsTeamsMeetingPolicy | Select-Object -Property Identity, RecordingStorageMode
# Below updated code

Install-Module -Name MicrosoftTeams -Force -AllowClobber
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credential
Get-CsTeamsMeetingPolicy | Select-Object -Property Identity, RecordingStorageMode

Sunday, January 31, 2021

Add user to Azure Data lake workspace Group using PowerShell

$GroupdID = "7519627166" # ID of the group where users need to be added as a member
$bearer_token = "dapi4defcba7682aff5-2"
$workspaceURL ="https://adb-85238717.17.azuredatabricks.net"
#----------------------------------------------------------------------------------------

$url = "$workspaceURL/api/2.0/preview/scim/v2/Groups/$GroupdID"
$headers = @{Authorization = "Bearer $bearer_token"}
$par = '{
  "schemas":[
    "urn:ietf:params:scim:api:messages:2.0:PatchOp"
  ],
  "Operations":[
    {
    "op":"add",
    "value":{
        "members":[
           {
              "value": "287484517  - ID of the user which needs to be added into above group"
           }
        ]
      }
    }
  ]
}'

Invoke-WebRequest $url -Method PATCH -Headers $headers -Body $par -ContentType 'application/json'

Get the list of user details for Azure Data lake workspace

$bearer_token = "dapi4de9600e2aff5-2"
$headers = @{"Authorization"= "Bearer $bearer_token"
"Content-Type" = "application/json" }
$hosturl="https://adb-8523889618.17.azuredatabricks.net"
$uri="$hosturl/api/2.0/preview/scim/v2/Users"
Invoke-RestMethod -Method 'Get' -Uri $uri -Headers $headers

Wednesday, January 27, 2021

Add user to Azure Data lake using Powershell with Admin access role.

# Script to add the user to Azure Data Lake workspace with allow-cluster-create access

$url = "https://adb-5890072754.14.azuredatabricks.net/api/2.0/preview/scim/v2/Users"
$groupid= "736317399920" # Get the Admin ID from the other script
$bearer_token = "dapie53ab46ca47e3e3a69f12a75c6-2"

$headers = @{Authorization = "Bearer $bearer_token"}
$par = '{
  "schemas":[
    "urn:ietf:params:scim:schemas:core:2.0:User"
  ],
  "userName":"databrickser-2@globeduc.onmicrosoft.com",
  "displayName":"User 2",
  "groups":[
    {
    "value":"$groupid"
    }
  ]
}'

Invoke-WebRequest $url -Method Post -Headers $headers -Body $par -ContentType 'application/json'

Add user to Azure Data lake using PowerShell

# Script to add the user to Azure Data Lake workspace with allow-cluster-create access

$url = "https://adb-58900332754.14.azuredatabricks.net/api/2.0/preview/scim/v2/Users"
$bearer_token = "dapie53af3e778b46c69f12a75c6-2"
$headers = @{Authorization = "Bearer $bearer_token"}
$par = '{
  "schemas":[
    "urn:ietf:params:scim:schemas:core:2.0:User"
  ],
  "userName":"databricksuser-2@globaleduc.onmicrosoft.com",
  "displayName":"User 2",
  "entitlements":[
    {
    "value":"allow-cluster-create"
    }
  ]
}'

Invoke-WebRequest $url -Method Post -Headers $headers -Body $par -ContentType 'application/json'

PowerShell Script to get the Admin Group ID from the Azure Data Lake workspace

# Script to get the Admin Group ID from the Azure Data Lake workbook

$bearer_token = "47e3e3a69f1676c6-2"
$headers = @{"Authorization"= "Bearer $bearer_token"
"Content-Type" = "application/json" }
$hosturl="https://adb-54.14.azuredatabricks.net"
$uri="$hosturl/api/2.0/preview/scim/v2/Groups"
Invoke-RestMethod -Method 'Get' -Uri $uri -Headers $headers

#-------Below Result Output ---------------------------------------------------
totalResults : 2
startIndex   : 1
itemsPerPage : 2
schemas      : {urn:ietf:params:scim:api:messages:2.0:ListResponse}
Resources    : {@{displayName=users; members=System.Object[]; groups=System.Object[]; id=718921211231112107551}, @{entitlements=System.Object[]; displayName=admins; members=System.Object[]; 
               groups=System.Object[]; id=736317356711920}}

Monday, January 18, 2021

Reassign Sways from a deleted user account

 https://support.microsoft.com/en-us/office/reassign-sways-from-a-deleted-user-account-admin-help-9580e618-3c3e-4d28-a6ef-74c00a997248?ui=en-us&rs=en-us&ad=us

HTML

Script:

JS