From time to time I come across this need; where I need to scrub a file where there are duplicates, there are blank lines, the sort order is all wack, and it just needs to be formatted to where it can be more readable and/or usable. This method just doesn’t apply to text, but also…
Author: mo wasay
A chart describing CIDR subnets
Admins need to understand some basic networking concepts like CIDR. These are needed when working with AntiSpam & Archiving providers. Here is a simple chart describing the CIDR subnets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
32 = X-network-bits + Y-host-bits Addresses = 2 ^ Y-host-bits -------------------------------------------------------------- CIDR Total number Network Description: Notation: of addresses: Mask: -------------------------------------------------------------- /0 4,294,967,296 0.0.0.0 Every Address /1 2,147,483,648 128.0.0.0 128 /8 nets /2 1,073,741,824 192.0.0.0 64 /8 nets /3 536,870,912 224.0.0.0 32 /8 nets /4 268,435,456 240.0.0.0 16 /8 nets /5 134,217,728 248.0.0.0 8 /8 nets /6 67,108,864 252.0.0.0 4 /8 nets /7 33,554,432 254.0.0.0 2 /8 nets /8 16,777,214 255.0.0.0 1 /8 net -------------------------------------------------------------- /9 8,388,608 255.128.0.0 128 /16 nets /10 4,194,304 255.192.0.0 64 /16 nets /11 2,097,152 255.224.0.0 32 /16 nets /12 1,048,576 255.240.0.0 16 /16 nets /13 524,288 255.248.0.0 8 /16 nets /14 262,144 255.252.0.0 4 /16 nets /15 131.072 255.254.0.0 2 /16 nets /16 65,536 255.255.0.0 1 /16 -------------------------------------------------------------- /17 32,768 255.255.128.0 128 /24 nets /18 16,384 255.255.192.0 64 /24 nets /19 8,192 255.255.224.0 32 /24 nets /20 4,096 255.255.240.0 16 /24 nets /21 2,048 255.255.248.0 8 /24 nets /22 1,024 255.255.252.0 4 /24 nets /23 512 255.255.254.0 2 /24 nets /24 256 255.255.255.0 1 /24 -------------------------------------------------------------- /25 128 255.255.255.128 Half of a /24 /26 64 255.255.255.192 Fourth of a /24 /27 32 255.255.255.224 Eighth of a /24 /28 16 255.255.255.240 1/16th of a /24 /29 8 255.255.255.248 5 Usable addresses /30 4 255.255.255.252 1 Usable address /31 2 255.255.255.254 Unusable /32 1 255.255.255.255 Single host -------------------------------------------------------------- |
In networks larger than a /31, one address is used for the network number, another for the broadcast address, and generally another as the default…
Delete Files and Folders Older Than X Days
Often times admin have to creates tasks like removing log files or some other files on a regular schedule. Here is an automated way of removing files / folders older than X days. Create a Batch file or Powershell script and add it to scheduled task. Batch File:
1 2 3 4 5 6 7 8 9 10 11 12 |
@echo off :: set folder path set dump_path=c:\shares\dump :: set min age of files and folders to delete set max_days=7 :: remove files from %dump_path% forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path" :: remove sub directories from %dump_path% forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path" |
Powershell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# set folder path $dump_path = "C:\shares\dump" # set min age of files $max_days = "-7" # get the current date $curr_date = Get-Date # determine how far back we go based on current date $del_date = $curr_date.AddDays($max_days) # delete the files Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item |
Set password never to expire for users in a particular domain (Bulk mode)
Let me start by saying that I don’t recommend doing this at all. Password Never Expires is bad security practice, but there are situations that might require it. I had a similar request on how this could be done. Setting it for multiple users:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#Connect of Office365 Import-Module MSOnline $O365Cred = Get-Credential $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection Import-PSSession $O365Session Connect-MsolService –Credential $O365Cred #Get a List of user that belong to the second domain $SDusers = Get-MsolUser -All -DomainName "yourseconddomain.com" #Setting the password never to expire ForEach($SDuser in $SDusers) { Set-MsolUser -UserPrincipalName $SDuser -PasswordNeverExpires $true } |
Setting it for a single user:
1 |
Get-MSOLUser -UserPrincipalName user@domain.com | Select PasswordNeverExpires |
Get PasswordAge for users in a particular domain
In Office365 if you have more than one domain in a subscription, there are times where you may want to get the password age for users of that domain. In my case to check which users are covered and meeting policy and get the users addressed.
1 |
Get-MsolUser -All -DomainName "yourdomainname.com" | select DisplayName, LastPasswordChangeTimeStamp,@{Name=â€PasswordAgeâ€;Expression={(Get-Date)-$_.LastPasswordChangeTimeStamp}} |
The output will be similar to:
How to force update GlobalAddressList in Office 365?
This post explains how to manually force and update the global address list in Office 365. Updating the global address list requires to have the Address List Management role. By default, nobody has this role. 1. Assign the AddressList Management role Login with your administrator account to the Office 365 portal. Go to Exchange Admin…
Remove disabled users from Distribution Lists & Security Groups in Active Directory
One of my clients had several disabled users showing up in distribution lists and security groups and this was creating unnecessary noise in email, alerts, etc. I highly encourage all administrators to keep their AD neat and tidy. The following PowerShell script searches for disabled users in Groups and Distribution Groups and removes them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# This script removes all disabled users from all security and distribution groups in the specified "searchOU" Import-Module ActiveDirectory $searchOU = "OU=Groups,DC=domain,DC=local" $adgroup = Get-ADGroup -Filter 'GroupCategory -eq "Security" -or GroupCategory -eq "Distribution"' -SearchBase $searchOU $adgroup | ForEach-Object{ $group = $_ Get-ADGroupMember -Identity $group -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | ForEach-Object{ $user = $_ $uname = $user.Name $gname = $group.Name Write-Host "Removing $uname from $gname" -Foreground Yellow Remove-ADGroupMember -Identity $group -Member $user -Confirm:$false } } |
…
Configure SNMP on an ESXi Host or multiple Hosts
Recently I needed to configure all of our 40 or so ESXi hosts to forward SNMP traps to our corporate monitoring solution. This meant enabling and configuring SNMP on each of the hosts. Naturally, I wrote a script for this as 40 hosts is way too many to do manually. This article shows you how…
Convert resource mailbox to a user mailbox
Based on my audit for a client I found that a user mailbox was at sometime converted to a resource mailbox. There is no convert button/ link to switch it back. I still don’t know how, or why this would have happened. Anyways, for someone who may come across this weird issue, here is the…
Find out ‘in cloud’ Distribution Groups
Microsoft Teams was announced yesterday and many want to jump right in. I noticed when users wanted to create teams, new distribution groups started getting added. I wanted to find out my ‘In cloud’ distribution groups and was surprised there was no property for the item. I was able to find out the groups…