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.

Please check permissions on the files and folders. If you have unique or specialized permission on the file or folders these wont work.

Batch File:

Powershell:

 

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:

Setting it for a single user:

 

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.

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 center, Permissions and admin roles.
    • Create a new role group and assign the AddressList role.addresslistrole

2. Update the AddressList

Once you have the AddressList role assigned, you can use the powershell commands to update the address list. You will have to wait for sometime until the new cmdlets are available.

  • First thing, logon to Exchange online using PowerShell.
  • Run the command Get-AddressList and verify that it’s working. (This may take some to work after creating the role)
  • Run Set-AddressList -Identity All users
  • Your address book is now updated

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:

Hope this helps!

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 configure SNMP on an ESXi host manually, via PowerCLI and via host profiles.

Option 1: Manually via Command Line

This is the most boring approach and should really only be used if you only have a few ESXi hosts to do, or if you really like doing things manually 🙂

  1. Start the SSH service on the ESXi host (Configuration >> Software >> Security Profile >> Services)
  2. SSH into host (using putty or something similar)
  3. Run the following to configure SNMP settings, enable SNMP in the firewall and start the SNMP agent:
    Note 1: Replace <COMMUNITY_STRING> with the community string for your monitoring solution.

    Note 2: Replace <TARGET_STRING> with the target string that maps to your environment, in the format of [email protected]/community_string.

    Option 2: Manually via PowerCLI

    Option number 2 is to use PowerCLI to configure SNMP on an ESXi host. The following script is how to do this on a single host. To configure SNMP on an whole bunch of ESXi hosts, see option 3 below.

    Note: Prior to being able to use the script above, ensure you configure the following variable values:

    • <ESXI_HOST> – The FQDN or the IP address of the ESXi host you want to enable SNMP on.
    • <COMMUNITY> – This is the community string you require for your environment (same as in option 1 above).
    • <TARGET> – This is the FQDN or IP address of the target you want to send the SNMP traps to. Note: THIS IS NOT A TARGET STRING as in option 1. In this instance you ONLY need the FQDN or IP address. The @port and the community_string will be added automatically by the Set-VMHostSnmp cmdlet.
    • <PORT> – The port you require SNMP traps to be sent on.

Option 3: Automatically via PowerCLI

If you have to configure SNMP for more than just a handful of ESXi hosts, then it is worth automating the entire process through a PowerCLI script. The logic around enabling SNMP on the ESXi host is the same as in option 2 above, with some additional logic around this to enumerate and complete the process on all ESXi Hosts.

Here is a script that will connect to a vCenter Server, get a list of all ESXi Hosts and then configure SNMP on each ESXi host:

Note: Similar to option 2 above, you will need to configure the following variables first:

  • <COMMUNITY> – This is the community string you require for your environment (same as in option 1 above).
  • <TARGET> – This is the FQDN or IP address of the target you want to send the SNMP traps to.
    Note: THIS IS NOT A TARGET STRING as in option 1. In this instance you ONLY need the FQDN or IP address. The @port and the community_string will be added automatically by the Set-VMHostSnmp cmdlet.
  • <PORT> – The port you require SNMP traps to be sent on.

Option 4: Automatically via Host Profiles

Finally, if you are lucky enough to be running Enterprise Plus licensing, then you will have the ability to use Host Profiles. This allows you to configure SNMP within the host profile and then just apply that profile to all of your ESXi hosts.

Follow these steps to add the SNMP configuration into an existing Host Profile:

  1. From the VI Client, navigate to Management >> Host Profiles
  2. Select the profile you want to add the SNMP settings and click Edit Profile
  3. Expand the SNMP Agent Configuration policy and select SNMP Agent Configuration
  4. In the Configuration Details pane, complete the followng:
    • Enable or Disable agent: Ticked
    • IP/UDP Port: The port you require SNMP traps to be sent on
    • SNMP Community String: The community string for your environment
    • Notification Receiver: The target string that maps to your environment, in the format of [email protected]/community_string
  5. Click OK to save changes
  6. For each ESXi host attach and apply the profile (Note: An ESXi host needs to be in maintenance mode to be able to apply the host profile)

And that concludes how to configure SNMP on a ESXi host.

Source

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 fix for it.

This will convert it from a shared mailbox, or a resource mailbox to a user mailbox.

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.

633466

 

I was able to find out the groups using the following:

This listed the information I needed to clean up groups.

You may also want to disable ‘group creation’ for users. Read how to do that here.

 

Migrate Office365 Photos to AD

Many of my customers have Office365 and have been using Skype for Business for sometime now. It is likely that your organization users have uploaded their profile picture. Now only if there was a way to sync those pictures back to your AD – so it looks neat & nice. There is a way!

Source

Create a Virtual Machine with 2 NICs in Azure Classic

Unfortunately, in Azure you cannot create a Virtual Machine in the GUI with 2 Network Cards. You cannot even add a 2nd NIC to a VM once it has been created. The only way to create a VM with 2, is to specify the additional NIC’s at the time of creation and ONLY via powershell. I have compiled a Powershell script that will do this. I have also listed the commands next to each comment to get the value to put there. Copy the code below into a PS1 and launch it from a PowerShell window.