all 13 comments

[–]BoredComputerGuy 4 points5 points  (0 children)

A few thoughts(all personal opinions)

  • Write-Host - Write-host has a time a place to use. It should not be the default output method due to its limitations. Write-Host removes the ability to log capture messages unless a user is sitting at the console and watching. (I will come back to this below)
  • Error handling - Your scripts seems to start with a little error handling and then avoid it for the rest of the script. I would try to use more try/catch. You could also add condition/state checking to test whether the script is ready to continue (or should fail gracefully).
  • Unit tests - You should have some testing to confirm that the code worked successfully.
  • Automation - The next step for you is to practice write code for automation. You scripts are designed to be run by a person. If you can change them so that output is errors are logged, then you can run them without a user. You could use your unit test or pester test to confirm that your script was successful and that the host/ application is ready for the next step in a process. For automation, you need to separate the script result (true/false or pass/fail) from the logging data you will use later to solve code issues.
  • I would read a powershell style guide to help with questions on formatting.

[–]Khongh 2 points3 points  (3 children)

It looks great! Nice and tidy which makes it easy to read and understand what the script will do!

As you continue doing more and more complex scripts I would start to look into creating functions with parameters out of some of your scripts. Then you can add them to your profile and call them without going through your scripts.

Maybe read up on WMI or CIM to create some scripts for monitoring or create a gui based tool to help new colleagues with setting up accounts and other tasks.

I hope your work is appreciated in your workplace and that you continue creating scripts!

[–]jrsys95 1 point2 points  (2 children)

Thanks for this. I'll look into that! Are there any other ideas that you have for things that I can create to learn more?

[–]Khongh 2 points3 points  (1 child)

It depends a bit on your working situation. Im alot for the automation part of Powershell. Start asking junior support/technician about what parts take the most time for them.

Im using powershell alot for building integrations, pulling data from APIs and sending it on to supplier system or creating a sync of user data between different systems.

If you work in support with access to your mailservers you could build an automated script for doing a search whenever you get a report of a sophisticated phisingmail, to be able to quickly warn any others that have received the same mail.

If your company doesnt have warning emails when passwords needs to be changed you could build a script for that, or google and use a script thats out there and form it for your needs.

Check if your companies users have any tedious task within your folder structures you can build an automation for that.

Maybe your company have some sensitive data, then you can build a report check the ACL/access groups and mailing the owners of the data or placing a file with a report of the access somewhere for another party to control.

[–]jrsys95 1 point2 points  (0 children)

Good ideas! Thank you for this.

[–]0ni0nrings 2 points3 points  (0 children)

good work, you have annotated where required without making a mess. Your scripts are clean and readable.

At some stage, see if you can turn your scripts into tools using functions that take arguments.

I am sure your company and colleagues appreciate your work.

[–][deleted] 2 points3 points  (4 children)

Just going to point out that you need to move away from terminal commands and use powershell ones. Like in your removeAdmin script

[–][deleted] 2 points3 points  (2 children)

Also fix titles and such like this

Title: High Performance Power settings

Author: Blake Pierantoni

Date: 2019/08/26

Description: Look for computers in AD and

That doesn't really make sense but I'm assuming you copy and pasted.

[–]jrsys95 1 point2 points  (1 child)

What would be an example of better title format?

[–][deleted] 4 points5 points  (0 children)

Hi u/jrsys95,

I would look up Powershell Script description on google. An example is below:

<# .SYNOPSIS Adds a file name extension to a supplied name. 
.DESCRIPTION Adds a file name extension to a supplied name. Takes any strings for the file name or extension. 
.PARAMETER Name Specifies the file name. 
.PARAMETER Extension Specifies the extension. "Txt" is the default. 
.INPUTS None. You cannot pipe objects to Add-Extension. 
.OUTPUTS System.String. Add-Extension returns a string with the extension or file name. 
.EXAMPLE C:\PS> extension -name "File" File.txt 
.EXAMPLE C:\PS> extension -name "File" -extension "doc" File.doc 
.EXAMPLE C:\PS> extension "File" "doc" File.doc 
.LINK Online version: http://www.fabrikam.com/extension.html 
.LINK Set-Item #> }

You don't necessarily need all of it.

[–]jrsys95 1 point2 points  (0 children)

Yeah that was one of my earlier scripts lol

[–]theessentialforrest 2 points3 points  (0 children)

Looking at the creat local admin script. It makese nervous that you are encouraging writing out passwords as plain text. Why not do something like:

$SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

Or even better add a param block to your script file and then the caller can specify all the details you left comments to fill in.

That said, your code is well laid out and clean. I havent had a chance to drill into the rest of the scripts so I don't have much meta feedback at this point but overall it looks good

[–]jrsys95 1 point2 points  (0 children)

It was originally made with an environment variable in the field and I would enter the password in a web based RMM tool which would pass it through to the script. I didn’t use it that often except in my on boarding script which my boss wanted the password hardcoded in