r/PowerShell • • Dec 28 '24

Question Does PowerShell make you look smarter?

215 Upvotes

I realized this question is rhetorical and ego stroking. I have found that knowing PowerShell makes me an asset at work. I am able to create reports and do tasks that others cannot. I have also been brought into several projects because of my knowledge.

Recently I had some coworkers jokingly tell me that the GUI was faster. A task that took them days to do I was able to figure out the logic with PowerShell in an hour. Now I can do thousands of their task at a time in a few minutes. They were impressed.

I am curious if others in the community has had similar experiences?


r/PowerShell • • Jun 30 '20

Script Sharing Sharing a few scripts I created over the past years, any edits/recommendations are more than welcome

214 Upvotes
  1. Figure out what locked a user in AD by using this script, the output will return a username, endpoint device that locked the user, what DC received the event & a timestamp.

$DC = Get-ADDomainController -Filter * | Select Hostname 
$properties = @(
    @{n='User';e={$_.Properties[0].Value}},
    @{n='Locked by';e={$_.Properties[1].Value}},
    @{n='TimeStamp';e={$_.TimeCreated}},
    @{n='DCName';e={$_.Properties[4].Value}}
)
Foreach ($D in $DC)
{
Get-WinEvent -ComputerName $D.Hostname -FilterHashTable @{LogName='Security'; ID=4740} | 
Select $properties
}

2. Figure out who shutdown a server, if it was by a user or an application did it. The output will return timestamp, user, reason they wrote & if it was a shutdown or reboot

$properties = @(
    @{n='TimeStamp';e={$_.TimeCreated}},
    @{n='User';e={$_.Properties[6].Value}},
    @{n='Reason/Application';e={$_.Properties[0].Value}},
    @{n='Action';e={$_.Properties[4].Value}}
)
Get-WinEvent -FilterHashTable @{LogName='System'; ID=1074} | 
Select $properties | Sort-Object "$_.TimeCreated"

3. A minor script to gather OS information from servers on your domain the output will return;

Servername, OS, RAM, Free space on C, and totalsize of C, can easily add more drives to monitor / gather information from.

$Serverlist = Get-ADComputer -Filter * -Properties OperatingSystem, DnsHostname | Where OperatingSystem -Like "*Server*" |  Select DnsHostname
$MasterList = @()

foreach ($Server in $Serverlist) {

$MyObject = New-Object PSObject -Property @{
Servername = $Server.DnsHostname
OS = (Get-CimInstance -ComputerName $Server.DnsHostname -ClassName Win32_OperatingSystem).Caption
RAM = (Invoke-command $Server.DnsHostname {(systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()})
CFreeGB = (Invoke-Command $Server.DnsHostname {(Get-WmiObject win32_logicaldisk -Filter "DeviceID='C:'").FreeSpace / 1gb -as [int]})
CTotalGB = (Invoke-Command $Server.DnsHostname {(Get-WmiObject win32_logicaldisk -Filter "DeviceID='C:'").Size / 1gb -as [int]})

}
$MasterList += $MyObject
}
# Select fields in a specific order rather than random.
$MasterList | Select Servername, OS, RAM, CTotalGB, CFreeGB  | Export-csv C:\Users\$env:username\Desktop\ServerOverview.csv -NoTypeInformation -Encoding Unicode

4. This script will prompt you for a servername, when entered it will create 2 AD-groups

"Servername Remote" & "Servername Admin" and give it the needed descriptions to differenciate between the two. When the group is created it will remote powershell to the server you entered and add the groups into the respective local groups so "Servername remote" goes into "Remote desktop users" and "Servername admin" goes into "Administrators" local groups. This way it is easy to manage who have access to what, and fast to create.

$ServerName = Read-host 'Enter servername'

New-ADGroup -Name "$ServerName Remote" -Description "Remote Desktop permissions to $ServerName" -GroupCategory Security -GroupScope Global -Path "OU=Groups,DC=domain,DC=com"
New-ADGroup -Name "$ServerName Admin" -Description "Local administrator permissions to $ServerName" -GroupCategory Security -GroupScope Global -Path "OU=Groups,DC=domain,DC=com"

Timeout 5

Invoke-Command $ServerName -ScriptBlock {Net Localgroup "Remote Desktop Users" "domain.com\$Using:ServerName Remote" /add}
Invoke-Command $ServerName -ScriptBlock {Net Localgroup Administrators "domain.com\$Using:ServerName Admin" /add}

r/PowerShell • • Jul 29 '18

Script Sharing PSWinDocumentation - Documentation for Active Directory

214 Upvotes

I've now released PSWinDocumentation - https://evotec.xyz/hub/scripts/pswindocumentation-powershell-module/

One command in #powershell and you've full forest information. Of course this is just basic information. Will require some work, polish and so on.


r/PowerShell • • Apr 20 '18

Script Sharing Azure speed test tool for PowerShell

213 Upvotes

r/PowerShell • • Feb 17 '19

Information How to sign a PowerShell script

Thumbnail
scriptinglibrary.com
212 Upvotes

r/PowerShell • • Sep 17 '19

New version of Win10-Initial-Setup-Script was just (Sept-11) released. Here is a line-by-line guide on how to use it.

211 Upvotes

Line by Line description of what Win10-Initial-Setup-Script does

Disassember0 just released the lastest version (3.8) of the Win10-Initial-Setup-Script on September 11th, 2019.

It's an awesome powerful script that you can one-click customize Windows 10 how you like it, force the removable of bloatware, force uninstall shit you don't need or want taking up resources, and also disable Microsoft spying on you and whatnot.

BUT, it's also a potentially very dangerous script and you can mess things up IF you don't know what you are doing. The documentation is very poor to non-existent in describing exactly what each option does, so I went through, line by line (about 200 lines) and explained exactly what each of them does. Hope this helps. Took me a whole day to figure them all out.

If I got something wrong or could be more clear, feel free to let me know. I'll fix it right quick.

Enjoy.


r/PowerShell • • Mar 17 '25

I really LOVE tiPS

209 Upvotes

https://github.com/deadlydog/PowerShell.tiPS

Ever since I let this load up in my profile at startup, I spend at least once a day to actually read the tip. And every time, I discover tons of stuff on how things can be written better, or how I can have a better development environment, or things that will make my life easy. Loads of pretty awesome stuff everyday. Today it I learnt about PSREADLINE and its predictive autocompletion based on history. It prompted me to just share this cause its awesome. Thank you Deadlydog!


r/PowerShell • • Mar 19 '21

Misc Request from a IT Tech College Teacher

209 Upvotes

Hey guys/gals/non-binary pals,

I just wanted to make a request as someone who just found out I have to rewrite my entire scripting class. If someone posts asking for help with something that seems like homework (or in my case a practical final), especially if they post the full text of the assignment as part of the question, please don't just respond with a code-block that does what the assignment is supposed to.

I know, being able to flex your scripting skills is good, I'm guilty of it myself, but unless you want a co-worker in the future that just outsources all their scripts, help me in giving them hints and links to documentation they should read up on, don't just do the project for them. I am trying to teach them how to learn about scripting, and now I am in the unenviable position of either running a class next quarter that if a student searches the a snippet of the assignment in quotes on google it takes them to 6 different scripts written by users of this sub, or rewriting 90% of my class because a former student crowd sourced everything.

I know this isn't really going to make a difference, but I had to ask just for my own sanity. Also if you see someone posting looking for homework answers maybe direct them to their instructors office hours, I would love to help them learn to learn, instead of learn to copy and paste random blocks of code from the internet.

Thanks for listening, and being a great resource. I don't blame any of you, I'm just trying to provide you with the best possible future co-workers.

Kevin


r/PowerShell • • Jan 17 '21

Script Sharing A PowerShell Template For Creating The Perfect Function

Thumbnail
thesysadminchannel.com
209 Upvotes

r/PowerShell • • Jan 24 '20

Pop up a SimCity-style PowerShell loading screen

209 Upvotes

r/PowerShell • • Dec 24 '25

Another Christmas gift for r/PowerShell

208 Upvotes

I’d like to share a must-have PowerShell GitHub repository for Microsoft 365 admins.

This repo features around 200 ready-to-use scripts to manage, report, and audit your Microsoft 365 environment effortlessly:

https://github.com/admindroid-community/powershell-scripts

Most scripts are scheduler-friendly, making it easy to automate recurring administrative tasks and save time.


r/PowerShell • • Nov 15 '20

What's the last really useful Powershell technique or tip you learned?

206 Upvotes

I'll start.

Although I've been using PowerShell for nearly a decade, I only learned this technique recently when having to work on a lot of csv files, matching up data where formats & columns were different.

Previously I'd import the data and assign to a variable and reformat. Perfectly workable but kind of a pain.

Using a "property translation" during import gets all the matching and reformatting done at the start, in one go, and is more readable to boot (IMHO).

Let's say you have a csv file like this:

Example.csv

First_Name,Last Name,Age_in_years,EmpID
Alice,Bobolink,23,12345
Charles,DeFurhhnfurhh,45,23456
Eintract,Frankfurt,121,7

And you want to change the field names and make that employee ID eight digits with leading zeros.

Here's the code:

$ImportFile = ".\Example.csv"

$PropertyTranslation = @(
    @{ Name = 'GivenName'; Expression = { $_.'first_name' } }
    @{ Name = 'Surname'; Expression = { $_.'Last Name'} }
    @{ Name = 'Age'; Expression = { $_.'Age_in_Years' } }
    @{ Name = 'EmployeeID'; Expression = { '{0:d8}' -f [int]($_.'EmpID') } }    
)

"`nTranslated data"

Import-Csv $ImportFile | Select-Object -Property $PropertyTranslation | ft 

So instead of this:

First_Name Last Name     Age_in_years EmpID
---------- ---------     ------------ -----
Alice      Bobolink      23           12345
Charles    DeFurhhnfurhh 45           23456
Eintract   Frankfurt     121          7

We get this:

GivenName Surname       Age EmployeeID
--------- -------       --- ----------
Alice     Bobolink      23  00012345
Charles   DeFurhhnfurhh 45  00023456
Eintract  Frankfurt     121 00000007

OK - your turn.


r/PowerShell • • Sep 17 '20

PowerShell vs Python Reference

Thumbnail blog.ironmansoftware.com
206 Upvotes

r/PowerShell • • Apr 03 '19

Misc I was today years old...

205 Upvotes

When I found out that ctrl+L clears the screen in the same fashion as I would clear the screen in bash...

Mind is kinda blown by this right now...what other cool things have you guys come across?


r/PowerShell • • Dec 06 '22

Misc Problem with Downvoting Powershell Questions

203 Upvotes

This subreddit has a big problem with people using the downvote function to ruin questions people come here to ask. I know it's easy to forget, but I doubt very few people come on here to casually ask Powershell questions for their fun time side gigs. A lot of people here are professionals who are coming here to ask questions because they have a task that they are stuck on.

Many IT people are not the best at asking cohesive questions, many of us spend our days thinking in logic rather than grammar. If you need to have OP reword their question or make their question more concise, give that kind and constructive criticism. Beyond someone asking questions that simple google searches would answer, like "How do I stop a service with powershell?" there should be no reason anyone has their questions downvoted. It's super irresponsible and very passive aggressively toxic for the community.


r/PowerShell • • Feb 18 '21

News Microsoft announces a new PowerShell Community Blog

Thumbnail
devblogs.microsoft.com
202 Upvotes

r/PowerShell • • Oct 15 '19

PSScriptMenuGui v0.2 now in PowerShell Gallery

202 Upvotes

r/PowerShell • • Oct 20 '20

Information This may help people learning how to use RoboCopy.

201 Upvotes

I see a lot of RoboCopy help requests on Powershell and a few other subs related to Win Server administration. I wanted to share this tool that really helped me understand all of the functions as switches with RoboCopy. During script development, I found that when wanting to use a RoboCopy function I would have to halt the creation of the script to test out the RoboCopy cmdlet and make sure it works.

The Tool: http://tribblesoft.com/easy-robocopy/

This helped me get really comfortable with the switches of robocopy as the best part about it is that it gives you the command to just copy into your code once you selected everything you wanted it to do!

I hope this helps you as much as it has helped me.


r/PowerShell • • Sep 29 '19

I made a module to download depressing lock screen images fresh every day, it's now available on the powershell gallery

Thumbnail
blob.pureandapplied.com.au
201 Upvotes

r/PowerShell • • Aug 06 '19

Misc The 2 verbs that make me hit backspace extra hard

Post image
200 Upvotes

r/PowerShell • • Oct 17 '18

PowerShell is the #4 fastest growing language of 2018 on GitHub

Thumbnail
octoverse.github.com
200 Upvotes

r/PowerShell • • Oct 16 '17

Your vote is requested: -NoTypeInformation should be default on Export-Csv · Issue #5131 · PowerShell/PowerShell

Thumbnail
github.com
200 Upvotes

r/PowerShell • • Aug 07 '21

Information PSA: Enabling TLS1.2 and you.

199 Upvotes

Annoyingly Windows Powershell does not enable TLS 1.2 by default and so I have seen a few posted scripts recently using the following line to enable it for Powershell:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

This does what is advertised and enables TLS 1.2. What it also does that is often not mentioned, is disable all other TLS versions including newer protocols. This means if an admin or user has enabled TLS 1.3 or new protocols, your script will downgrade the protections for those web calls.

At some point in the future TLS 1.2 will be deprecated and turned off. If your script is still running (nothing more permanent that a temporary solution,) and it is downgrading the TLS version you might find it stops working, or worse opens up a security issue.

Instead you want to enable TLS 1.2 without affecting the status of other protocols. Since the Value is actually a bitmask, it's easy to only enable using bitwise or. So I suggest that instead you want to use the following code:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12

I don't think it will affect anyone now, but maybe in a few years you might have avoided an outage or failed process.

I just wanted to awareness of an easily miss-able change in what their code might be doing.


r/PowerShell • • Apr 04 '20

Information How NOT to find installed applications (and how to do it properly)

199 Upvotes

A few hours ago I read yet another article (from merely a week ago) that recommended querying the Win32_Product WMI class to find installed apps. This is definitely not a good way to do it, and after seeing it recommended for years I decided to write a short post on why, and a different way of going about it.

Hopefully it saves someone a bit of pain.

https://xkln.net/blog/please-stop-using-win32product-to-find-installed-software-alternatives-inside/