Managing Local User Profiles Buildup

Powershell
Obviously there's a GPO for this... ...but it's a bit rubbish and the computer needs a restart for it to ever work and I also didn't want to wipe out Staff Local User Profiles, I only cared about getting rid of Old Student User Profiles, I do this to ensure there's enough disk space on the machines, luckily student usernames are all numbers so this was easy to do. Get-WMIObject -Class Win32_UserProfile | Where-Object {(!$_.Special) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-3)) -and ($_.LocalPath.Split('\')[-1] -match '^\d+$') } | Remove-WmiObject By using PowerShell, we can query WMI and delete old profiles on the machine. The following bit of PowerShell above will ensure special user profiles are not deleted and only delete profiles that are older than 3 days old, obviously you can change this…
Read More

Email Alert when a certificate is set to expire soon

Powershell
So I needed a script that I could run as a scheduled task that would alert me if there were any certificates that were due to expire soon from our servers. Some of our web servers will need their certificates renewing in the future that can't be auto-renewed so thought this was the best time to put something in place to automatically alert the team when a certificate is due to expire and so action can be made ahead of time instead of when it happens. I adapted my script  from the following blog article here, found that the script was buggy and would stall if a server was offline or if there was an issue with invoking the command remotely so I had introduced an if statement first to…
Read More

Staff member user account creation script

Powershell, Windows
Sharing is caring, right? Here is a powershell script I wrote that creates new users based on their First name and surname, checks to see if a username exists from their first name in AD, if it does append the first letter from their surname and use that as their username, if that exists, append the next letter, etc. I also have logic to set and create the user's home drive, add the account to the correct security groups, create a remote mailbox, begin a delta sync on Azure AD Connect, log to a text file for audit purposes and print off a word document to pass on details to new user. [code language="powershell"] #New Staff Account Creation Script, Created by NCK - Last Revised 14/05/2018</code> #DECLARED VARIABLES $Colours =…
Read More