• 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 November 23, 2022

November 23, 2022 by ClaytonT Leave a Comment

As we are approaching the holiday season  at the end of the year, dates are very important. Everything from counting down the days to the new year to creating those end of the year reports.

With that said, how many times have you had to create a report for the previous month, but it’s  parameters are only StartDate and EndDate? Now, you have to remember how many days are in that month and consider if it’s a leap year or not. And sometimes the first of the month is on a weekend, Holiday, or a day you took PTO so you have to make sure your code doesn’t just go back 30 days as then it may or may not get the whole previous month.  And let’s say for reasons you can’t control,  you can’t have it as a scheduled task to always run on the first of the month?

This one liner(technically 2 one for StartDate and one for EndDate), is the solution you need. It will check which month your in, go to the previous month then find the first and last day of that month. That’s it!

$StartDate = (Get-Date -Day 1).AddMonths(-1).ToString("yyyy-MM-dd")

$EndDate = (Get-Date -Day 1).AddDays(-1).ToString("yyyy-MM-dd")

If you wanted the past 6 months you could change the -1 to -6 in Start Date. Now you don’t have to manually enter the month date range every time you need a report for the previous month. You could set this as the default parameter, but give yourself the option to change it if you need a different date range.

Documentation:

Get-Date:
Microsoft Learn

Tagged With: Get-Date, One Liner Wednesday, PowerShell, Reporting

One-Liner Wednesday November 16, 2022

November 16, 2022 by ClaytonT Leave a Comment

Always love when you get surprised by printer issues? Here is a one liner that in its current state works great, but can be expanded on to be even more powerful, or gives you an idea to go more in depth.

 invoke-command -computername ServerName -credential YourUser  -scriptblock {get-printer | select-object name, printerstatus, portname}

This code will connect to your print server or user computer and check all printers installed and their status. It’s not limited to one computer for situations where you have multiple printer servers or need to check on multiple user computers. It will even show when toner and paper jams. Wouldn’t it be nice to see if the user is even connected to the printer they are trying to print to or if the printer is saying there is a paper jam?

To go a step farther, you could set this up as a scheduled task or have it monitor, and send a toast notification, create a ticket depending on the error, or send a chat message to your teams/discord/slack channel. To go even more granular, you could connect to the printer’s API and check toner levels, and have it order that toner when it hits the pre-determined threshold.

Hoping this little one liner helps out, and gives you some more ideas on how you can expand on it, to make your lives easier. If you have a related script, please post it in the comments for more ideas.

PowerShell Help:
Get-Printer

Tagged With: One Liner Wednesday, PowerShell, Print Management

One-Liner Wednesday Nov 9, 2022

November 9, 2022 by ClaytonT Leave a Comment

This is an oldie, but a goodie…

Unlock-ADAccount -Identity "UserName"

If you haven’t used this, and didn’t know it existed, definitely add it to your tool box. It’s so much easier than having to go into the GUI to do this.

A nice future script you could have this in is if you have multiple users get locked out, that you could pipe Get-ADUser for the group you want and filter it so only disabled show and either unlock all of them, or pipe it to Out-GridView with passthrough. This would give you a nice gridview of the users and the ones you select from it would be disabled.

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

One-Liner Wednesday November 2, 2022

November 2, 2022 by admin Leave a Comment

Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |
Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} | sort-object ExpiryDate

Here is a one liner that find very useful and hope you do to.

You can customize it even more, but for now this one grabs all the AD User accounts that are expiring and the ones expiring first at the top. I love using this to stay in front of users passwords expiring then they can’t connect or if they are off network and is a rush to get it done.

You could even sent this up as a scheduled task and have it pull the next 2 weeks of users. Then either you reach out to them, it emails them, or it notifies your help desk to reach out to them to help change their password.

Or you could have it in your dashboard so you’d always see the next 2 weeks of users passwords expiring.

Tagged With: AD, One Liner Wednesday, Passwords, PowerShell, Windows Server

One-Liner Wednesday October 26, 2022

October 26, 2022 by ClaytonT Leave a Comment

One Liner Wednesday Cyber Security Edition

Want to see the top Malware that hits your 365 Exchange? Try this one liner out

Get-MailTrafficSummaryReport -Category TopMalware -StartDate 08-01-2022 -EndDate 10-25-2022 | Select-Object C1,C2 | out-gridview

This will give you the different types of malware Microsoft has found and how many times it found in since August 1. Then it will display it in a grid view that you can filter. I normally export to Excel/CSV to keep the data as it goes away after 90 days. Bigger organizations I’d recommend pushing it into a database for longer term analytics.

Check out Microsoft Docs and my 365 GitHub Repository for more ideas!

Microsoft Documentation:
Get-MailtrafficSummaryReport

365 Exchange Security Dasboard(Very early stages)
365 Exchange Security Dashboard

My Microsoft 365 GitHub Repository:
Powershell365

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

One-Liner Wednesday October 19, 2022

October 19, 2022 by ClaytonT Leave a Comment

New-TenantAllowBlockListItems -ListType Sender -Block -Entries emailaddress

Here is a super useful one liner that has come in handy more recently.

What this does is adds a user or domain to the tenant block list as it’s written below. If you need to add someone to the allow list, you can change -Block to -Allow. You can even change set a duration for both Blocking and Allowing.

Command:
New-TenantAllowBlockListItems

Example with Parameters:

Add-365Blocklist

Tagged With: One Liner Wednesday, PowerShell, Security

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Page 4

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