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

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

Automation

Extracting Excel Worksheet Names to a CSV

April 14, 2023 by ClaytonT Leave a Comment

I know it’s Friday, but I’m changing it a bit up today. I just created this little script that I think could be helpful to others. This one isn’t for the masses, but I have a feeling it will help out more than a few people, and trigger some more ideas for script ideas.

# Specify the path to the Excel file
$excelFilePath = "C:\Scripts\WorksheetTitle.xlsx"
$outputCsvPath = "C:\Scripts\exportworksheetlabels.csv"

if (!(Test-Path $ExcelFilePath)) {
    Write-Error "Excel file not found at the specified path: $ExcelFilePath"
    return
}

# Open the Excel file
$excel = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList (Get-Item $excelFilePath)

# Get the worksheet names
$worksheetNames = $excel.Workbook.Worksheets | ForEach-Object { $_.Name }

# Add quotes around each worksheet name and convert them to a comma-separated string
$commaSeparatedWorksheetNames = ($worksheetNames | ForEach-Object { '"' + $_ + '"' }) -join ','

# Export the worksheet names to a CSV file
$commaSeparatedWorksheetNames | Set-Content -Path $outputCsvPath

# Dispose the ExcelPackage object to release resources
$excel.Dispose()

What this script does, is takes all of your worksheet names in an excel sheet, and exports them with quotes and commas as if they were an array. An example would be “Dog”, “Cat”, “Cheetah”, where Dog, Cat, and Cheetah were the 3 different worksheet names. Don’t ask how I picked those names, but I’d be curious to see who has those worksheet names in an excel workbook!

Now you are probably wondering what the use case for this is, and for me, which I found very useful was we have an excel workbook that is separated by job title. And inside each of these worksheets are the 365 Distribution/Security Lists and 365 Groups for that title. This makes it so we have one “database” of lists, and only need to make the change once, if a standard changes. This works for both adding and removing them. But, the user who is adding/removing these groups for that user, needs to know the exact title for that user and how it is spelled on the worksheet…

This is why we export the titles this way, so then we can copy and paste them into a validateset within the function for the script, so the user has tab completion and so the script won’t even start without having the correct title.

Hope this helped you out and/or gave you some more ideas, and if you see anyway it can be improved, I’m all about being more efficient. Let me know if you would want to see the script to add users by title from an excel worksheet. Have a great Friday!

Github – Copy-ExcelWorksheetName

Tagged With: 365, AD, Automation, Excel, PowerShell

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

Module Monday March 20, 2023

March 20, 2023 by ClaytonT Leave a Comment

Hope you had a great weekend, and are ready for today’s Module Monday. Are you using Duo security? Or looking at Duo for your company? Then you need this module. It’s called DuoSecurity.

Why not automate the process of onboarding/terminating employees or removing old phone authenticators? What about reporting on who is in which groups, how many phones they have, or filtering event logs?

So many more things to automate with this module and make your life easier as well as make your company more secure.

If you have used this module before, let me know how you are using it.

PowerShell Gallery:
Duo Security

GitHub:
Duo Security

Tagged With: Automation, MFA, Module Monday, PowerShell, Reporting, Security

Read-Only Friday March 10, 2023

March 10, 2023 by ClaytonT Leave a Comment

It’s Friday, and I’m going to keep this one short in sweet copy. I’ve mentioned this module before, but it is so helpful if you use any of the products, that I want to make sure you don’t miss out on it! Yes, I know it’s Read-Only Friday, but this module will step up your documentation game ten fold.

AsBuiltReport on Github or you can find them on asbuiltreport.com.

What they have created is multiple modules depending on the product you need documentation on, and with one quick line of code, you get a full breakdown of the product you requesting information on. How about a 144 page document on your Active Directory? Not bad, right?

Check them out, and let me know what you think!

GitHub:
https://github.com/AsBuiltReport

Website:
https://www.asbuiltreport.com/

Tagged With: AD, Automation, Documentation, Fortigate, Fortinet, Module Monday, PowerShell, Read-Only Friday, Reporting, Veeam, VMWare, Windows Server

One-Liner Wednesday March 8, 2023

March 8, 2023 by ClaytonT Leave a Comment

Are you using VMWare? Ever had to troubleshoot why a VM isn’t working? Or need to know the status of a virtual machine? If you haven’t used PowerCLI before(I know I’ve mentioned it previously), check out this one liner.

 get-vm servername | select-object name, powerstate, usedspacegb, provisionedspacegb

What this does is first finds the server you are looking for with “servername.” Then it shows the server name, whether it is turned on or off, how much storage space is used, and finally how much storage is provisioned. This gives you a very quick overview of the status of the server.

I know, very simple, but it works… and you can expand on this. You could not put a servername in, and it will show all of your virtual machines with the information above.

What about if you have 100s or even 1,000s of servers, you could export to gridview or even better to excel with the importexcel module for filtering.

Hope you found this useful, and if your not already using the PowerCLI module to start using it and make your life easier.

PowerShell Gallery:
PowerCLI

Tagged With: Automation, Documentation, PowerCLI, PowerShell, Reporting, VMWare, Windows Server

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