• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

One Liner Wednesday

One-Liner Wednesday August 2, 2023

August 2, 2023 by ClaytonT Leave a Comment

Have you ever needed to create multiple 365 Groups/Security/Distribution at one time? This could be for a new department, new office, or even a new campaign that only certain people need access and email to. I won’t even go into the time it would take to do this in the GUI, but how would you add them scripting wise, as there are 4 types of Groups/Lists in 365. Do you only do one cmdlet at a time and hope someone doesn’t come back after you’ve already done some and they need to add another group with a cmdlet you’ve already used?

I have a nice simple one-liner to fix this issue.

Add-CT365Group -FilePath "C:\\Path\\to\\file.xlsx" -UserPrincialName "admin@domain.com" -Domain "domain.com"

That’s it.

Ok, to be fair, PowerShell wise that is all there is to it other than installing the 365AutomatedLab module from Github. After that only 3 steps needed, and well worth it. Here are the steps:

  1. Create a workbook in Excel, and have a sheet named “Groups”
  2. Add the Headers “DisplayName”, “PrimarySMTP”, “Description”, “Owner”, and “Type”
    1. DisplayName is self explanatory as this will be the Display name for the group
    2. PrimarySMTP is the email address without the @domain.com
    3. Description is self explanatory as this will be the description value for the group
    4. Owner is only a placeholder, but will be adding that soon
    5. Type will be the type of group it is – and will pull the corresponding cmdlet
      1. 365Group
      2. 365MailEnabledSecurity
      3. 365Distribution
      4. 365Security
  3. Add your Group information in the corresponding fieldsExcel worksheet example

After those are filled in, you can run the script from above pointing to where you saved that excel file, and all those groups you added to the Excel worksheet named “Groups” will be added (As long as you have the correct permissions)

It’s really that simple. I’m looking to expand the properties you can add into the groups, if there are any you’d rather see first, please let me know.

I hope you found this useful and it saves you time/headaches from having to more manually add them! As always if I can help out in anyway, please feel free to reach out!

Microsoft Documentation on Group Types

New-UnifiedGroup

New-DistributionGroup

New-MgGroup

Tagged With: 365, 365AutomatedLab, Automation, Groups, One Liner Wednesday, PowerShell

One-Liner Wednesday July 26, 2023

July 26, 2023 by ClaytonT 1 Comment

Ever needed to check a computer or server and see how much disk space is being used? It could be for multiple reasons such as are any disks too low on space, too much available space assigned(think VMs where you need storage for a new server, but assume all of your storage is tied up), or you just need to see drives that have more than a certain amount of free space due to company standards.

This little one-liner is a great template for you then. This one liner will show any drive on the current computer that has more than 30gb of space free. You could easily change the “-gt” to “-lt” and only show drives with less than 30gb of space free.

Get-PSDrive -PSProvider 'FileSystem' | Where-Object { ($_.Free / 1GB) -gt 30 } | Format-Table -AutoSize

I know your thinking, I can easily click on my computer and check hard drive space, but what about if you have 10, 100, or 1000+ devices you have to manage? Do you really want to do all of those clicks? You could even set this up as a scheduled task and have it notify you, send to teams/discord/etc, or even email a Distribution List with a report. That sounds like a lot better idea than wasting time clicking around.

If your curious on how to have this capture multiple computers, one way is:

$Computers = 'Computer1', 'Computer2', 'Computer3'  # Replace with your computer names or IPs

$ScriptBlock = {
    Get-PSDrive -PSProvider 'FileSystem' | 
    Where-Object { ($_.Free / 1GB) -gt 30 } | 
    Format-Table -AutoSize
}

foreach ($Computer in $Computers) {
    Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock
}

I hope you found this one-liner useful, and would love to hear how you use it or have used it in the past! And as always if you have any questions, please feel free to reach out and if I can’t help you out, and I can find someone that can.

Tagged With: Automation, Disk Usage, One Liner Wednesday, PowerShell, Reporting, Windows Server

One-Liner Wednesday March 29, 2023

March 29, 2023 by ClaytonT 2 Comments

Can you believe it’s Wednesday already? I can’t either, week is flying by. Could it be the excitement of the PowerShell + Devops Global Summit coming up in a few weeks? Quite possibly! If you haven’t gotten your ticket yet, I highly recommend it. With that said, these next 3 weeks I’ll be highlighting speakers and topics from the summit.

Today’s one-liner is a great one for troubleshooting from Jeff Hicks. He will be heading the Onramp program for attendees who are just getting into IT. It is such a great program and wished it was around when I was getting into IT!

Get-WinEvent -FilterHashtable @{Logname = 'System';Level=1} -MaxEvents 10 | sort-Object ProviderName,TimeCreated

What this one-liner does is searches the System Event Log for the last 10 “Critical” events. Then sorts them by the Provider name and date/time. You could change the level for “lesser” events if needed. Also if you need to check on a remote computer you can add the -ComputerName parameter, but remember that it only takes 1 computer at a time. If you need to connect to multiple computers, you can use ForEach to reach out to all computers needed.

Hope this one-liner helps you out and hope to see you at the PowerShell + DevOps Summit!

Jeff Hicks:
Blog

PowerShell + DevOps Global Summit:
Global Summit

Microsoft Learn:
Get-WinEvent

Tagged With: Automation, Event Log, One Liner Wednesday, PowerShell, Reporting, Windows, Windows Server

One-Liner Wednesday March 22, 2023

March 22, 2023 by ClaytonT Leave a Comment

We made it to Wednesday, so now we get a PowerShell One-Liner to make your life easier. Here’s the scenario, HR comes to you and says you need to forward Mark Smith email to John Ralph as soon as possible. Instead of opening up your 365 Exchange Admin portal and logging in, then finding Mark Smith, then finding the Forward option, then typing in John Ralph’s email and saving it.

All you need to do is your Connect to 365 Exchange Portal with Secrets” script, then run

Set-Mailbox msmith@email.com -FowardingAddress jralph@email.com

That is it! Seriously, that’s all you need to do. If your not doing anything else with 365 right away, I would disconnect the session.

One Parameter you can add is -DeliverToMailboxAndForward $true, which will save email sent to the original intended email, but still forward the email as well.

Hope this helps you out, and I’ve used this before in other scripts and created functions to add even more functionality.

PowerShell Help:
Microsoft Learn

Tagged With: 365, Automation, One Liner Wednesday, PowerShell

One-Liner Wednesday March 15, 2023

March 15, 2023 by ClaytonT Leave a Comment

Today’s one-liner may not be a direct PowerShell command, but it can be run inside the PowerShell terminal. Are you using Intune, or looking into using Intune? If your already using it, you know by default when you add a user it sets them as a local administrator(I’m not sure exactly why, but that can be a topic for another blog post), and of course we don’t want our users to be local administrators on their computers. To resolve this issue, all you need to do is remove them from the local administrators group like below.

net localgroup administrators azuread\user@domain.com /delete

The only change needed is changing “User@domain.com” to their login address. I’d recommend adding this to your new device script, and if you do not have a new device script, I’d start one now, so you can keep adding and automating things to save you time and have consistent deployments.

Also, take a look at Azure Functions to see how you can deploy code and automate things on a bigger scale.

Tagged With: AzureAD, Intune, One Liner Wednesday, PowerShell, Windows

One-Liner Wednesday February 22, 2023

February 22, 2023 by ClaytonT Leave a Comment

Ever wanted a quick and easy way to see what operating systems all your computers are running to the detail of the version number? Then wanting to know the last time they logged on?

PowerShell provides a powerful and efficient way to perform this task. In this blog post, we will show you how to use a PowerShell one-liner to search for computers in a specific OU and view their name, operating system, OS version, and last time they logged in.

Searching for computers in a specific OU

You can start by searching for computers in a specific OU. The “Get-ADComputer” cmdlet can be used to retrieve information about computer objects in Active Directory. Here is an example command that retrieves all computers in the “Computers” OU:

Get-ADComputer -SearchBase "OU=Computers,DC=example,DC=com" -Filter * -Properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate

This command uses the “-SearchBase” parameter to specify the distinguished name of the search base where the search should be conducted. In this case, we are searching in the “Computers” OU of the “example.com” domain. You should replace this with the distinguished name of the OU you want to search in.

The “-Filter” parameter is used to retrieve all computer objects in the specified OU, and the “-Properties” parameter is used to specify the properties you want to retrieve. In this case, we are retrieving the “Name”, “OperatingSystem”, “OperatingSystemVersion”, and “LastLogonDate” properties.

Formatting the output

The output of the previous command is not very user-friendly, so we need to format it to make it easier to read. We can use the “Select-Object” cmdlet to select the properties we want to display and format the output using the “Format-Table” cmdlet. Here is the final PowerShell one-liner:

Get-ADComputer -SearchBase "OU=Computers,DC=example,DC=com" -Filter * -Properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate | Select-Object Name, OperatingSystem, OperatingSystemVersion, @{Name="LastLogonDate";Expression={[DateTime]::FromFileTime($_.LastLogonDate)}} | Format-Table -AutoSize

This command retrieves all computer objects in the specified OU and selects the “Name”, “OperatingSystem”, “OperatingSystemVersion”, and “LastLogonDate” properties. The “LastLogonDate” property is converted to a readable date format using the “FromFileTime” method of the “DateTime” class. Finally, the output is formatted using the “Format-Table” cmdlet to display the information in a table format. You could even change “Format-Table” and use “Out-GridView” to give you an excel like experience where you can filter and sort columns… and to make it even more advance if you are trying to remove or disable computers, you could use the Out-GridView with a “-PassThru” parameter then pipe it to a delete or disable. ***Make sure to use -WhatIf so you don’t by accident delete all of the computers that you searched for!

Conclusion

In this blog post, we have shown you how to use a PowerShell one-liner to search for computers in a specific OU in your Active Directory and view their name, operating system, OS version, and last time they logged in. This information can be very useful for managing your domain and keeping track of your computers. This can be used for reporting and for autoamating tasks that only pertain to certain versions of Windows OS. By using PowerShell, you can quickly and easily retrieve this information and format it in a way that is easy to read and understand while using it for automations.

Tagged With: AD, Automation, One Liner Wednesday, PowerShell, Reporting, Windows Server

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »

Primary Sidebar

Clayton Tyger

Tech enthusiast dad who has lost 100lbs and now sometimes has crazy running/biking ideas. Read More…

Find Me On

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Recent Posts

  • New Feature Announcement for 365AutomatedLab
  • How ChatGPT saved our company $1500 in less than 15 minutes
  • Read-Only Friday August 4, 2023 End Of Life Server 2012R2 and managing EOL
  • One-Liner Wednesday August 2, 2023
  • Module Monday July 31, 2023

Categories

  • 365
  • Active Directory
  • AI
  • AzureAD
  • Cim
  • Dashboards
  • Documentation
  • Get-WMI
  • Learning
  • Module Monday
  • Nutanix
  • One Liner Wednesday
  • Passwords
  • PDF
  • PowerShell
  • Read-Only Friday
  • Reporting
  • Security
  • Windows
  • WSUS

© 2023 Clatent