Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Admin Check
- param([switch]$Elevated)
- function Test-Admin {
- $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
- $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
- }
- if ((Test-Admin) -eq $false) {
- if ($elevated) {
- # tried to elevate, did not work, aborting
- } else {
- Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
- }
- exit
- }
- 'Running with full privileges'
- #Get Admin Credentials
- Write-Host "Please use your full email address as your username"
- $UserCredential = Get-Credential
- #Authenticate with Office
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- #Connect to Exchange
- Import-PSSession $Session -DisableNameChecking
- #Get CSV path to import
- Write-host "Please Enter the full file path to the csv file"
- $path = Read-Host "Full File Path to CSV"
- Write-Host "Path is set to " $path
- #CSV Format Example
- #Members,Identity
- #bob@contoso.com,Distribution Group 1
- #sally@contoso.com,Distribution Group 2
- #Set CSV Headers
- $member = "Members"
- $distname = "Identity"
- #Do WhatIf First so I can grab and easy to read log
- Import-csv -Path $path | ForEach-Object { Add-DistributionGroupMember -Identity "$($_.$distname)" -Member "$($_.$member)" -Confirm:$false -WhatIf }
- Import-csv -Path $path | ForEach-Object { Add-DistributionGroupMember -Identity "$($_.$distname)" -Member "$($_.$member)" -Confirm:$false }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement