Skip to content

Instantly share code, notes, and snippets.

View SibeeshVenu's full-sized avatar
🙂
Learning and Sharing

Sibeesh Venu SibeeshVenu

🙂
Learning and Sharing
View GitHub Profile
USE [master]
GO
/****** Object: Database [TrialsDB]
CREATE DATABASE [TrialsDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'TrialsDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'TrialsDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
@SibeeshVenu
SibeeshVenu / send-out-of-office-message-outlook-powershell.ps1
Created March 11, 2021 15:40
PowerShell function to configure the out of office reply message automatically for all the holidays in your calendar, provided set up the calendar by following this blog: https://www.msoutlook.info/question/show-holidays-as-busy-or-out-of-office
Function Configure-OutOfOffice-Message
{
Add-Type -AssemblyName 'Microsoft.Office.Interop.Outlook'
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNameSpace('MAPI')
$Calendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar
$folder = $namespace.getDefaultFolder($Calendar)
$Holidays = $folder.items |
Select-Object -Property Start, Categories | Where-Object Start -ge (Get-Date).AddDays(-1) | Where-Object Categories -eq 'Holiday'
Foreach($holiday in $Holidays)
$appName = "appname"
$apiName = "apiname"
$apiUri = "https://<tenantname>.onmicrosoft.com/api.access"
$secretStartDate = Get-Date
$secretEndDate = $secretStartDate.AddYears(10)
$myAdApp = New-AzureADApplication -DisplayName $appName -Oauth2AllowImplicitFlow $true -AvailableToOtherTenants $true
$myAdApi = New-AzureADApplication -DisplayName $apiName -AvailableToOtherTenants $true -KnownClientApplications $myAdApp.AppId -IdentifierUris $apiUri
$secret = New-AzureADApplicationPasswordCredential -ObjectId $myAdApi.ObjectId -CustomKeyIdentifier "GraphClientSecret" -StartDate $secretStartDate -EndDate $secretEndDate
$secret
$appName = "appname"
$appHomePage = "companyhomepage"
$secretStartDate = Get-Date
$secretEndDate = $secretStartDate.AddYears(10)
$myAdApp = New-AzureADApplication -DisplayName $appName -HomePage $appHomePage -Oauth2AllowImplicitFlow $true -AvailableToOtherTenants $true
$secret = New-AzureADApplicationPasswordCredential -ObjectId $myAdApp.ObjectId -CustomKeyIdentifier "GraphClientSecret" -StartDate $secretStartDate -EndDate $secretEndDate
$secret
$appName = "appname"
$appUri = "appuri"
$appHomePage = "homepageuri"
$myAdApp = New-AzureADApplication -DisplayName $appName -Oauth2AllowImplicitFlow $true -AvailableToOtherTenants $true -IdentifierUris $appUri -HomePage $appHomePage
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
namespace < YOURNAMESPACE > {
public interface IGraphAuthService {
GraphServiceClient GetGraphServiceClient(Guid tenantId);
}
using System;
using System.Threading.Tasks;
using Microsoft.Graph;
namespace < YOURNAMESPACE > {
public interface IGrapFacade {
Task < IGraphServiceUsersCollectionPage > GetUsersUsingGraph(Guid tenantId);
}
public class GraphFacade: IGrapFacade {
public async Task < IEnumerable < UserDto >> GetUserList(Guid selectedTenant) {
_logger.LogInformation($ "The method {nameof(GetUserList)} is called");
var appUsers = await _adminRepository.GetUsersWithRole(selectedTenant);
if (!appUsers.Any()) throw AdminException.FromCode(ErrorCode.NoUsersInDbSelectedTenant);
var users = await _graphFacade.GetUsersUsingGraph(selectedTenant);
if (!users.Any()) throw AdminException.FromCode(ErrorCode.NoUsersInAdSelectedTenant);
var combinedList = appUsers.Join(users, app = >app.UserId, graph =>new Guid(graph.Id), (app, graph) = >new UserDto {
DisplayName = graph.DisplayName,
[HttpGet("getusers")]
public async Task<IActionResult> GetUsers()
{
try
{
_logger.LogInformation($"The method {nameof(GetUsers)} is called");
var users = await _adminService.GetUserList(HttpContext.GetSelectedTenantId());
if (!users.Any())
{
_logger.LogCritical($"The method {nameof(GetUsers)} returned no users");