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

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

PowerShell

Getting Started with 365AutomatedLab Part 2

October 6, 2023 by ClaytonT Leave a Comment

Adding/Removing Groups

Adding and removing groups with 365AutomatedLab is as easy as it is for adding and removing users(If you missed part one, check out Getting Started with 365AutomatedLab Part 1) It can add and remove the 4 different groups(Group, Mail Enabled Security, Distribution, and Security) that 365 has from one excel sheet. As of right now it will fill in the Display Name, Primary SMTP, and Description. I’ll be adding more parameters, but wanted to get at least these available. What are some other parameters you want to see first?

Adding Groups

Now the fun part, adding groups with one line of code. But, first we need to have a worksheet named “Groups” with the column headers

  • DisplayName
  • PrimarySMTP
  • Description
  • Type

After you have created those, you can input the data that you want in those fields. Remember for type you will use 365Group, 365MailEnabledSecurity, 365Distribution, or 365Security, which will tell 365 what type of group you want created. If you don’t have test data feel free to go to the already premade Excel workbook in the LabSources section in the repository. Below is a quick snapshot of the Excel workbook.

Data all set? Let’s run this little One-Liner to import all these groups into 365!

New-CT365Group -FilePath C:\\Scripts\\LabSources\\365DataEnvironment3.xlsx -UserPrincipalName admin@yourdomainname.onmicrosoft.com -Domain yourdomainname.onmicrosoft.com

Depending on when you last logged in, you’ll have to confirm access twice, once for Exchange Online and once for Graph. If you don’t allow these, the script will look like it froze on you. Trying to save you some of the headaches that I went through!

Your 365 Portal should now look like this

All set! That’s really how easy it is!

Removing Groups

The beauty of this setup, is now you only have to one PowerShell command, and you are all set.

Remove-CT365Group -FilePath C:\\Scripts\\LabSources\\365DataEnvironment3.xlsx -UserPrincipalName admin@yourdomainname.onmicrosoft.com

All done, now all your groups in your Excel workbook are removed!

Summary

Wasn’t it easy? Testing larger data sets will be a breeze or setting up and removing tests. You should never have to test in a production environment, as you can copy those groups to the Excel workbook and import them into your Dev tenant. I hope you found this helpful and makes your life easier as it has mine. If you have any recommendations or questions, please feel free to reach out and/or create a Github Issue.

GitHub: 365AutomatedLab

Tagged With: 365, 365AutomatedLab, Automation, AzureAD, Entra, Excel, PowerShell

Getting Started with 365AutomatedLab Part 1

September 29, 2023 by ClaytonT 2 Comments

Adding/Removing Users

Adding Users

With 365AutomatedLab, you can add as many users with their primary licensing as you need at one time. Currently, the Microsoft Dev Environment only allows 25 licensed users, and one is your primary account, so the max I’d recommend creating is 24 users if you’ll only be using this in a dev environment.

Quickest way to get started is by opening the 365DataEnvironment Excel Workbook in the LabSources folder. Here you can see the formatting for the cells so that a user can be added. (Let me know if you would like more attributes added, as these are required and ones I felt would be most useful to start)

View of 365DataEnvinronment.xlsx

FirstNameLastNameUserNameTitleDepartmentStreetAddressCityStatePostalCodeCountryPhoneNumberMobilePhoneUsageLocationLicense
AliceJohnsonajohnsonIT SpecialistIT1818 Maple StAlbanyNY12207USA212-555-1234212-555-5678USDEVELOPERPACK_E5

If you want to use “real” data, I’d recommend exporting your users from your production environment that you want to test, which you can use “Export-CT365ProdUserToExcel” to do this if you don’t already have a script to do so. You will have to copy the information into the 365DataEnvironment.xlsx, as the export as of right now is using Microsoft default column headers and I need to change them to match the excel sheets.

Now that you have your data all set, it’s time to add them to your Dev tenant.

New-CT365User -FilePath "C:\\Path\\to\\file.xlsx" -domain "contoso.com"

The file path is exactly what it says and you are required to type out the .xlsx or it will fail. The domain will be the domain for your tenant, if its a dev tenant it should be domainname.onmicrosoft.com. Then it will ask you to type in a password that you will user for all users.

That’s it, now you have created all your users.

Deleting Users

Now say you are done testing with those users and you want to remove them, or something you were testing changed their information too much from their original state? All you need is this line of code, and they will all be removed.

Remove-CT365User -FilePath "C:\\Path\\to\\file.xlsx" -Domain "contoso.com"

After the magic of PowerShell happens, all those users will be gone. Nice and easy, right?

Summary

Hope you found this useful, as it has saved me many times/hours when testing different scripts and changing the source data too much, then having to remember the users information to delete. I was surprised when I hadn’t seen anything like this as I know there are so many people testing in 365, and why not make it easier? Please look out for the next part of this series where you’ll be able to add and remove all the different types of groups in 365.

As always feel free to reach out anytime, and let me know what you think as well! Have a great day!

365AutomatedLab

Tagged With: 365, 365AutomatedLab, Automation, MsGraph, PowerShell

Quick Use of OpenAI – End Processes

September 27, 2023 by ClaytonT Leave a Comment

Here is a quick use of OpenAI / ChatGPT to remove Windows processes. If it doesn’t get it right the first time, it usually is a good enough base to only need an edit or 2 for simpler scripts. Not bad for going 2/2 on no edits needed!

PROMPT 1:

Me:

You are a powershell expert, can you write me a script to find all processes running then show me them in a window and I can select which ones I want to delete?

ChatGPT:

Certainly! Here’s a PowerShell script that will retrieve all running processes, display them in a GUI window using Out-GridView, and then terminate the selected processes:


# Get all running processes
$processes = Get-Process | Select-Object Id, Name, CPU, Path

# Display processes in a GridView for selection
$selectedProcesses = $processes | Out-GridView -Title "Select processes to terminate" -PassThru

# Terminate selected processes
$selectedProcesses | ForEach-Object {
    try {
        Stop-Process -Id $_.Id -Force
        Write-Host "Terminated process: $($_.Name) with ID: $($_.Id)"
    } catch {
        Write-Warning "Failed to terminate process: $($_.Name) with ID: $($_.Id)"
    }
}

Steps:

  1. The script fetches all running processes and selects a few useful properties like Id, Name, CPU, and Path.
  2. The processes are then presented in a GridView window using Out-GridView. You can select multiple processes by holding down the Ctrl key and clicking on them.
  3. After you click “OK”, the script will attempt to terminate the selected processes.

Note: Ensure you have the required permissions to terminate processes. Also, be cautious about which processes you terminate, as some are essential for the proper functioning of your system.

Review 1:

You can see that it created the first prompt perfectly, and no edits were necessary.

Selected the processes and gave me a GUI to delete the ones I don’t need anymore

PROMPT 2:

ME:

Can you make it so I can select which one I want see beween ram and cpu?

ChatGPT:

Of course! We can add an initial prompt to let you select between viewing processes based on RAM or CPU usage.

Here’s the updated script:


# Get all running processes
$processes = Get-Process | Select-Object Id, Name, CPU, WS

# Prompt the user to choose between CPU and RAM
$choice = $host.ui.PromptForChoice("Selection", "Choose the metric to display top 5 processes:", @("CPU", "RAM"), 0)

# Display the top 5 processes based on the selected metric
if ($choice -eq 0) {
    $topProcesses = $processes | Sort-Object CPU -Descending | Select-Object -First 5
} else {
    $topProcesses = $processes | Sort-Object WS -Descending | Select-Object -First 5
}

# Display processes in a GridView for selection
$selectedProcesses = $topProcesses | Out-GridView -Title "Select processes to terminate" -PassThru

# Terminate selected processes
$selectedProcesses | ForEach-Object {
    try {
        Stop-Process -Id $_.Id -Force
        Write-Host "Terminated process: $($_.Name) with ID: $($_.Id)"
    } catch {
        Write-Warning "Failed to terminate process: $($_.Name) with ID: $($_.Id)"
    }
}

Now, when you run the script, it will first prompt you to choose between CPU and RAM. After you make your selection, it will display the top 5 processes based on that metric. You can then select which processes you want to terminate.

Review 2:

As you can see this worked exactly how I wanted it to and gave me the option to pick the top 5 highest of ram or cpu usage, then allowed me to delete.

Tagged With: Automation, PowerShell, Windows, Windows Server

New Feature Announcement for 365AutomatedLab

September 18, 2023 by ClaytonT Leave a Comment

I wanted to let everyone know as of this morning you can add and remove Teams and Teams Channels with only 1 line of code and an Excel Worksheet using 365AutomatedLab.

It’s as simple as this:

New-CT365Teams -FilePath "C:\path\to\365DataEnvironment.xlsx" -AdminUrl "<https://yourdomain.sharepoint.com>"

And to remove those teams:

Remove-CT365Teams -FilePath "C:\path\to\365DataEnvironment.xlsx" -AdminUrl "<https://yourdomain.sharepoint.com>"

Let me know what you think. Do you want the ability to add more than 2 additional channels? Any of the other parameters you would like added for teams and channels? Eventually, I’ll add them all, but rather start with the ones that you most use.

As always feel free to reach out and I’m always open to PRs.

365AutomatedLab

Tagged With: 365, 365AutomatedLab, Automation, PowerShell, Sharepoint, Teams

How ChatGPT saved our company $1500 in less than 15 minutes

September 15, 2023 by ClaytonT 1 Comment

Let me set the stage… previously we had a batch file in our startup script to add/remove network drives. It worked great and didn’t have any issues. We moved away from an on-site file server to a cloud solution with local cache. They created a new batch file for us which worked perfectly… until we started looking at integrating Intune computers. Luckily, early on we caught this, and realized we needed a PowerShell script instead of a batch script. We reached out to the vendor with knowing they had PowerShell experience and asked if they could recreate the script using PowerShell. They came back with a quote of $1,500.

I looked at the batch script again, and said there is no way it costs that much to convert an already working batch script to PowerShell. So what did I do? I opened up the 26 line batch script, skimmed over it, then copied it into ChatGPT, and told it to convert the script to PowerShell. It created a PowerShell function within the script and when I followed up with an additional prompt to see if a certain drive was still present to delete it, it created that as well. It was 98% done, I only had to fill in our company data and one part they had an additional parameter that wasn’t needed. All less than 15 minutes. For context, this was with ChatGPT with GPT-4 back in early May 2023, as it is even better now.

Is ChatGPT always this accurate? No, but when you search on Google, Stack Overflow, or any other site, is it always accurate? I like to think of ChatGPT, Azure OpenAI, etc as a smart intern where you trust, but verify the work before implementing. Always test in a development environment as some code take down infrastructure(Same with other sites/LLMs)

Now, not only did I save the company $1,500, I saved time from all the meetings, paperwork(Purchase Order and misc), and testing with the vendor which I used to work on other projects!

Hope you found this helpful and gets you thinking of using ChatGPT, Azure OpenAI, etc more, but please make sure you know what you are testing and/or are in a complete test environment. And if for some reason you take down something in production by accident, let someone know asap what you were doing, so that it can be quickly resolved if you aren’t sure how to fix it.

Tagged With: Automation, Azure OpenAI, ChatGPT, PowerShell

Read-Only Friday August 4, 2023 End Of Life Server 2012R2 and managing EOL

August 4, 2023 by ClaytonT Leave a Comment

Read-Only Friday August 4, 2023

Do you still have any Windows Server 2012R2 or earlier in production? This is a friendly reminder that they will be going End Of Life October 10 of this year. If you do have any in production, what is your plan to decommission them? Do you still need the server, or will you be spinning up a new upgraded VM? Do you have the licensing to upgrade? What are your next steps?

Talking about End Of Life, how do you manage and track your equipment and licensing for this scenario? Do you have special asset/license management software, SharePoint list, SQL Database, Excel workbook, or even a csv with dates and costs?

If you’ve made it this far, I’m hoping this isn’t a surprise and this is only a reminder to keep following your plan, but if this is the first time you’re hearing this, please look at this now and put a plan in place, especially if you will need to purchase new licensing. While you are at it, I’d check those servers running 2012R2 and see how much of the services you really need running now, as a lot has probably changed since you first put them into production. Also, do you have enough resources to run both at the same time, or do you have to take a current backup(test to make sure the backup works), delete(or turn off and hope you don’t accidently turn it on while new server is on) your current 2012R2, then build the new on?

Good luck with your migrations and as always if there is anyway I can help, feel free to reach out! Have a great Friday, and remember no unscheduled changes today.

Tagged With: Automation, Documentation, PowerShell, Read-Only Friday, Reporting, Windows Server

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 6
  • Page 7
  • Page 8
  • Page 9
  • Page 10
  • Interim pages omitted …
  • Page 19
  • 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

  • Learning ValidateSet in PowerShell: Valid Values Only
  • Teams Chat and PowerShell – How to add value!
  • EntraFIDOFinder: New Web UI and Over 70 New Authenticators
  • January 19, 2026 Updates to EntraFIDOFinder
  • v0.0.20 EntraFIDOFinder is out

Categories

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

© 2026 Clatent