Showing posts with label Techie. Show all posts
Showing posts with label Techie. Show all posts

Thursday, January 07, 2021

Techie Post - Deleting emails from multiple mailboxes in Office 365

Occasionally I'm asked at work to delete an email that has been accidentally sent out to the wrong people.  It doesn't happen very often, but inevitably when it does happen, I forget the process, so I am including it here for personal reference.

Create a content search rule within the Microsoft 365 Compliance area - https://compliance.microsoft.com/homepage  (take note of the name you call it - you'll need it in the New-ComplianceSearchAction command.

Run Powershell as administrator and enter the following commands...

set-executionpolicy remotesigned
(only use this if you get an error about not being able to run scripts via Powershell)

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

New-ComplianceSearchAction -SearchName "Rule Name used in content search" -Purge -PurgeType SoftDelete

If you would like to see the progress of the search, use the following command.

Get-ComplianceSearchAction


Monday, April 20, 2020

Technical Post - List Users of Active Directory Group

A small PowerShell script to list users in a specific Active Directory group

get-adgroup groupname | get-adgroupmember | sort name | % {$_.name}

groupname = The name of the AD group you wish to look at.

Sunday, August 25, 2019

Techie Post - Nested If in Excel for converting month to a number

This post is more of a reminder for me, but may help someone else in a similar situation.  Every year in August when I need to create the new user accounts for the students starting in September at school, I need the student date of births to be in the format DDMMYY so that my custom powershell script can create the accounts in Active Directory

Sounds simple, but alas our School Information Management System exports the data in a weird format, so I am always having to modify and fix the exported data in excel before I can import the completed csv file.

Most can be accomplished using the excellent left, mid and right formulas, but the date (more specifically, the month) always causes me issues.

So, where I a have a cell where the month is "Jan", or "Feb", I need it to be "01" for Jan, "02" for Feb and so on.

So.... assuming cell F2 is the cell with the month in it, the following nested If formula will do the job

=IF(F2="Jan","01",IF(F2="Feb","02",IF(F2="Mar","03",IF(F2="Apr","04",IF(F2="May","05",IF(F2="Jun","06",IF(F2="Jul","07",IF(F2="Aug","08",IF(F2="Sep","09",IF(F2="Oct","10",IF(F2="Nov","11",IF(F2="Dec","12",))))))))))))

Once I have the month as a number, I can easily combine the 3 numbers making up the day, month and year (ddmmyy) in to a cell for my script to accept.

I'm sure there's a better way of doing it, but hey ho...  This does the job for now.


Wednesday, April 10, 2019

Technical Post - Creating new Active Directory user accounts on Windows Server 2016 using Powerscript

A useful little Powerscript which I have written for student user creation in a Windows Active Directory.  Some features may not be useful to all since I wrote this for our needs in our school, but it's pretty straight forward to use and I'm sure it could easily be modified to fit someones needs if they wanted the same.  The script creates the user object in Active Directory, adds them to groups, creates their user folder (on a different server), and sets the correct permissions on that folder.

I've posted this here more of a reminder to me if I ever need to revisit it, and I'm sure there is probably a far better and efficient way of doing this, but it may help someone, somewhere!

A couple of things to bear in mind..  Our student username format begins with two digits, then the first three letters of their surname, and then the first three letters of their forename (ie 19WilStu).   AND obviously, any references to server names and folder locations will need to be updated with your details

Please feel free to comment, and let me know if you have a better way of doing it :D

Write-Host ""
Write-Host "  STUDENT USER CREATION SCRIPT (Powerscript V1)"
Write-Host "  ---------------------------------------------"
Write-Host "             By Stu -  09/04/2019"
Write-Host ""

# ---------------------------------------------------------------------
# -     LETS GET SOME VARIABLES AND CREATE THE USERNAME FORMAT        -
# ---------------------------------------------------------------------
#
$forename = read-host -prompt 'Input users forename'
$surname = read-host -prompt 'Input users Surname'
$year = read-host -prompt 'Input users year - (This is the number in their username eg. 15, 06, 03)'
$forename_Three = ($forename.SubString(0,3))
$Surname_Three = ($surname.SubString(0,3))
$username = $Year + $Surname_Three + $Forename_Three
Write-Host "Hello $username"

# ---------------------------------------------------------------------
# -              CHECK TO SEE IF USER EXISTS OR NOT                   -
# ---------------------------------------------------------------------
#
if (dsquery user -samid $username)
{
Write-Host "Found user - PLEASE RESTART AND START AGAIN"
Pause
exit
}
    else {"Did not find user - Let's continue to setup the user"}

$password = read-host -prompt 'Enter default password'
Write-Host ""
Write-Host " We have everything we need to create the user account. Please wait"
Write-Host ""


# ---------------------------------------------------------------------
# -             CREATE USER OBJECT IN ACTIVE DIRECTORY                -
# ---------------------------------------------------------------------
#
New-ADUser $username -AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) -ChangePasswordAtLogon $True -path "OU=Year$Year,OU=Pupils,OU=Domain Users,DC=yourdomain,DC=local" -Company "Year$Year" -DisplayName "$forename $surname" -Description "Initial Password is $password" -HomeDrive U -HomeDirectory "\\Yourfileserver\folder\students\userareas\Year$Year\$username" -HomePage "www.yourwebsite.com" -UserPrincipalName "$username@domain" -EmailAddress "$username@youremaildomain.com" -Enabled $True -SamAccountName $username -Surname $Surname -GivenName $Forename -ea Stop

Add-ADGroupMember -Identity "Pupils" -Members $username
Add-ADGroupMember -Identity Year"$Year"Group -Members $username

# ---------------------------------------------------------------------
# -           USER AREA FOLDER CREATION AND PERMISSIONS               -
# ---------------------------------------------------------------------
#
$samAccountName = $username
$fullPath = "\\Yourfileserver\folder\students\userareas\Year$Year\{0}" -f $samAccountName
$driveLetter = "U:"

$User = Get-ADUser -Identity $samAccountName

if($User -ne $Null) {
    Set-ADUser $User -HomeDrive $driveLetter -HomeDirectory $fullPath -ea Stop
    $homeShare = New-Item -path $fullPath -ItemType Directory -force -ea Stop
    $acl = Get-Acl $homeShare
    $FileSystemRights = [System.Security.AccessControl.FileSystemRights]"Modify"
    $AccessControlType = [System.Security.AccessControl.AccessControlType]::Allow
    $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
    $PropagationFlags = [System.Security.AccessControl.PropagationFlags]"InheritOnly"
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($samAccountName, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)
    $acl.AddAccessRule($AccessRule)
    Set-Acl -Path $homeShare -AclObject $acl -ea Stop
    Write-Host ("HomeDirectory created at {0}" -f $fullPath)


# ---------------------------------------------------------------------
# -This bit creates the default subject folders in the users user area-          -
# ---------------------------------------------------------------------

new-item \\Yourfileserver\folder\students\userareas\Year$Year\$username\Art -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Business -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Design -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Drama -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\English -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Food -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Geography -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\History -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\ICT -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Languages -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Maths -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Music -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\PE -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Personal -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\RE -itemtype directory
new-item \\Yourfileserver\folder\students\userareas\Year$Year\Science -itemtype directory

Clear-Host
Write-Host ""
Write-Host "User $username has now been created successfully"
Write-Host ""
Write-Host "Username : $username"
Write-Host "Password : $password"
Write-Host ""
Pause

Monday, December 08, 2014

Techie Tip : Powershell script for deleting emails by keyword for Exchange 2013

Another post meant for me because I am so forgetful, but it may be useful for others if they come across this.

OK, not one I need to use very often, but here is a quick script for when you need to delete an email with a specific keyword in the subject from multiple mailboxes




cls
Write-Host ""
Write-Host "The following script deletes emails from a named user/mailbox"
Write-Host "containing a specified string in the Subject of the email"
Write-Host ""

Write-Host "Please enter a name (* wildcards ARE ALLOWED)"
$name = Read-Host '>>'
$name

Write-Host ""
Write-Host "Please enter a SUBJECT' keyword (* wildcards ARE ALLOWED)"
$keyword = Read-Host '>>'
$keyword

Search-Mailbox -identity $name -SearchQuery "Subject:'$keyword'" -deletecontent
exit

Sunday, October 05, 2014

Techie tip : Revocation Check Failed when adding a certificate to a Microsoft Exchange 2013 installation

One for me to refer back to in the future in case it ever happens again.  We had a new Microsoft Exchange 2013 server installed during the school summer holiday and due to the school changing its name to "The De Montfort School", I had to purchase a new wildcard certificate for the domain tdms.worcs.sch.uk.

Anyway, after applying for the certificate, and eventually installing it, I got the message "Revocation Check Failed"

To cut a long story short, when running the following from a command prompt, I received this.....

C:\>netsh winhttp show proxy
Current WinHTTP proxy settings:
Direct access (no proxy server).


Essentially, Exchange wasn't using my servers proxy settings, so therefore could not contact the Revocation servers at Comodo (the supplier of our certificate).

Running the following command imports the proxy settings from Internet Explorer.  Once done, the server could perform the Revocation checks, and all of my certificates are now showing as valid and working....

C:\>netsh winhttp import proxy ie
Current WinHTTP proxy settings:
Proxy Server(s) :  10.0.0.27:3128
Bypass List     :  (none)


Easy when you know how!!!!!!