r/PowerShell • • 28d ago

Script Sharing What have you done with PowerShell this month?

A sticked post for the community to share their projects throughout the month.

Make sure to post a link to the code!

20 Upvotes

31 comments sorted by

10

u/MetaCardboard 28d ago

Get-aduser (user) properties -passwordexpired

5

u/BlackV 28d ago

you can also use

 Search-ADAccount -PasswordExpired

the other one I use probably daily

Search-ADaccount -LockedOut

and send that to (once i've validated the output)

Unlock-ADAccount

1

u/MetaCardboard 28d ago

If you know you want the account unlocked can you just pipe it all in one command? Will it still give you result of whether it's locked out or not and then unlock it after? Or does it have to be two separate commands?

2

u/BlackV 28d ago edited 18d ago

if you want to know the account, then just the search by its self (as i say you should probably do that for validation)

but yes, 100% you can just do

Search-ADaccount -LockedOut | Unlock-ADAccount

Edit: I guess you could throw a out-gridview or tee-object in there as well

2

u/Rogermcfarley 28d ago

I have a script which uses just get-aduser I use it to get all the AD user properties I need such as EXT , Is the account enabled/disabled is the password expired which OU is it in, the UPN the email, the date the account expires, which computers the account can connect to which login hours are set and I use some logic to colour some of the output in red using the inbuilt text color property. Then it outputs it to a nice simple table.

2

u/MetaCardboard 28d ago

I would love to learn to color some output. I usually just do "-properties *" and then scroll through too much garbage to find what I'm looking for.

3

u/Rogermcfarley 28d ago

2

u/MetaCardboard 28d ago

Thank you. I'm about to make my screen a rainbow just for fun. Well not right now, it's Sunday and I'm mildly hungover. But tomorrow instead of doing my job.

2

u/Rogermcfarley 28d ago

It's very easy to write some simple logic and display the output as you want. So you can have conditions if met the color changes. I use red only currently as that's all I need. If I see red on any of the text on an AD property then I can scan the output easily with my eyes and see the issue. Is the AD account locked it'll tell me Yes and highlight it red you don't need to even display the AD property you can get it to just say Yes or True/False whatever makes it easier to read quickly.

2

u/jibbits61 28d ago

There’s also a lolcat module, and of course you could use the normal lolcat.exe ported to windows. Pretty rainbows 🌈 🤩

4

u/arslearsle 28d ago

A few functions I use as a photograper
Convert canon eos raw cr2 files to jpg as preview to customer for selection, shrink size, reduce quality and use LAB color space for sharpening, stamp image number from filename on jpg file, and a stamp saying preview

wake up adobe lightroom - why you dont hsve these features

mush faster than adobe lightroom, as it uses ps 7 foreach -parallell

Also functions to make jpg images square for the idiotic instagram format, it mounts photo on top of a white square background, stamp image w logo, and you can choose LAB sharpen or standard sRGB sharpen (unsharp mask)

…and also a function that splits a photo into 9 proportional parts, of you want to make a little fun in an i instagtam post

last two is not async/parallell

uses imagemagick for image work

guess you vould do the same using . net but…it works nicely

3

u/JimsTechSolutions 27d ago

I use Enter-PSSession on a daily basis

2

u/Dapper_Librarian388 23d ago

Lol Im doing the same the lazy way - in ISE.

1

u/PL13DSCH 17d ago

Mit PSSession habe ich vor einigen Wochen begonnen, nutze jetzt aber hauptsächlich den Invoke Befehl

2

u/lan-shark 27d ago

I'm working a bit on PowerShell's syntax highlighting grammar. The project is in a bit of a sad state, unfortunately. The first issue is that the main branch doesn't even pass all the tests, there are two failures. So I have a PR out for that, hopefully it gets merged soon and I can make progress in other areas. While I wait on that, I'm exploring more options to test the grammar. The project is currently using the old Atom editor which was sunset in 2022 or something. I've tested a couple of newer drop-in replacements already and I'm about to start on exploring options for a more thorough rework with a newer stack

2

u/human193 25d ago

Packaging applications using PSADT

Remediating the node2shell on endpoints I had to compare current Nodejs version with target version. Nodejs doesn't have a build number when cast as a [version] so comparing to another version wouldn't work.

So to compare the versions I had to normalize them with $NodeVerNormalized = [version]::new($NodeVer.Major,$NodeVer.Minor,$NodeVer.Build) $22targetversion = [version]::new(22,23,4)

Repeated for version 24 and 26. 

Something I'd never done before. 

2

u/Respond-Creative 21d ago

Wrote a module for Microsoft Attack Simulator.

1

u/Droidoko 3d ago

Could you share it?

2

u/Respond-Creative 3d ago

Would love to. Need clearance first.

1

u/Respond-Creative 3d ago

1

u/RemindMeBot 3d ago

I will be messaging you in 28 days on 2026-12-24 19:51:34 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback

1

u/pleplepleplepleple 25d ago

Most notably an interactive Intune Remediation script to offer package manager updates to discovered WSL distros.

1

u/XxGet_TriggeredxX 23d ago

Created offline domain join script(s) for Zscaler.

1

u/BlackV 18d ago

Oh interesting, are you able to give more details

1

u/Vern_Anderson 9d ago

Added more comment based help to scripts I've written but never took the time to add the synopsis, description, and examples.

1

u/Vern_Anderson 9d ago edited 9d ago

Read a short and sweet explanation of ampersand, that is way more readable than the way I would have said it.

"The call operator (&) executes a command or script. Invoke-Expression executes PowerShell code."

Which one sounds bad to you?

1

u/SnooRobots3722 9d ago

In my day job I have a lot of "teams" meetings, and occasionally get the shout of "you're on mute", as I have a little USB MIDI button pad (an AKAI APCmini) I have had written a little script that lights the button green or red to show if I am mute (or not) and pressing it toggles the status in Windows

One advantage of this method is usb midi doesn't need drivers and powershell doesn't need any librarys so it can be used on a work laptop with accusation of installing anything.

Over time I hope to find a use for the twenty other buttons and the sliders!

https://github.com/backache/APCminiForWindowsControl

0

u/ToninoBaliardo 27d ago

"winget upgrade --all" to update software on my home computers.

1

u/BlackV 18d ago

It's a good command for sure, not PowerShell though

There is an official winget PowerShell module now called Microsoft.WinGet.Client, which also has a nice winger repair cmdlet too