87 votes
Accepted

Delete folder if it exists in PowerShell

I assume you're just trying to avoid the error message in case it doesn't exist. What if you just ignore it: Remove-Item $folder -Recurse -ErrorAction Ignore If ...
  • 1,769
14 votes
Accepted

Powershell search millions of files as fast as possible

First, you don't need to call Get-Date for every file. Just call it once at the beginning: ...
  • 1,663
9 votes
Accepted

Powershell Windows Service Deployment

Your code and overall logic look good. In general the areas of improvement I see are There are some things you are inconsistent about, e.g., function parameters You are sending notification ...
  • 2,548
8 votes

Delete folder if it exists in PowerShell

It is better to use pipeline syntax. If there are no files, then nothing will happen: Get-ChildItem $folder -Recurse | Remove-Item
  • 81
8 votes

Power-Guessing The Number

I have three points to make: GetNumber: The naming indicates it may be for integer conversion. While the truth is far from that, renaming might be a good idea. ...
  • 11.9k
8 votes
Accepted

Power-Guessing The Number

Needs more variables I see plenty of integer constants. They define the upper and lower bounds of the game. Let turn those into variables and define them. Makes the game easier to make changes. <...
  • 2,548
8 votes

Remove known Excel passwords with PowerShell

Once you've found the right password and moved the file, then there is no need to try the rest of the passwords on it. You can break out of the loop with a break ...
  • 1,663
7 votes

MD5 hash comparison for two folders

Better is subjective but I will try and improve the code your have here to make it more robust and scalable. I will try to cover areas of improvement or focus and bring it together in the end. A lot ...
  • 2,548
7 votes
Accepted

Powershell to quickly ping a number of machines

Want to start of with I am new to workflows as well. For the most part your code is solid. You should see a couple of suggestions that would actually improve performance especially if you are running ...
  • 2,548
6 votes

Getting a list of all computer objects in each AD domain

One thing that I notice, you can change this repetitive fragment ...
  • 211
6 votes
Accepted

Powershell to Convert HTML Table to Array of PSCustomObject

Parsing HTML I won't lay into you too badly about using RegEx on HTML since you clearly already know it's a bad idea and are trying to parse it as XML instead. Not a bad idea. I have to recommend ...
  • 1,769
6 votes

Find related groups among list of users

Purposeful PowerShell Help I see that you have some comments in your script. Those for the most part would be hidden inside the script and the only way someone would see them is to open it. This may ...
  • 2,548
6 votes

Adding some properties to an Active Directory user

Disclaimer: I never wrote code like that, I do not see a reason to do it and I discourage everyone to do it. This however may be seen as nothing else aside of a preference. But what are you trying to ...
  • 5,536
6 votes

PowerShell script to create Excel spreadsheet from HTML file

Your code looks fine. Just some notes: Excel The main weakness of your design as I see it is its reliance on the Excel application. Since you say robustness is important, Excel would be the main ...
  • 1,663
5 votes
Accepted

Fastest Windows script to move files from one did to a network dir

Okay, I'll start by trying to answer your questions first. If there is a lot of files and you should look into using runspaces to run several copy-jobs in separate threads. Just be careful, you are ...
  • 166
5 votes
Accepted

Query AD and build CSV based on certain user object properties

There are several changes I would propose here. I will try and tackle them one an a time. I will include some snippets as we go along but the end will contain the whole code. Redundant call to Get-...
  • 2,548
5 votes
Accepted

FizzBuzz: A PowerShell Story

Your code looks good to me. I like how it takes pipelined input. That is pretty elegant. You don't need the Position=0 here: ...
  • 1,663
5 votes
Accepted

Creating a portable encrypted credential store

I don't know enough about handling credentials to know whether the overall concept is sound, so I will ignore that aspect. I do have the following suggestions regarding the details of your code. Use ...
  • 166
5 votes

Sherlock is going against the Beast with PowerShell

I'm no powershell expert but if spaces sprinkled around here and there would make the code more readable. So instead of this: ...
  • 20.1k
5 votes
Accepted

Get AD Users' Latest Last Logon Dates across Multiple DCs

Aliases You're used to my reviews by now so you're probably tired of me saying this, but avoid aliases and abbreviations (% vs ...
  • 1,769
5 votes

Batch script to make folders hidden

I am glad you asked your question here. I'm hoping to explain why what you are trying to do is a bad idea. I cannot speak much for improving your batch as that is not my strong point but that should ...
  • 2,548
5 votes
Accepted

Cleanly setting ACLs

To streamline the permission handling you may want to wrap ACE creation in a function and set the ACL just once at after all ACEs were added: ...
5 votes
Accepted

Populate Comboboxes with Hashtables using PowerShell

The first thing to observe is that the five pieces of code are identical except for two parameters that are varying. We can capture the common the code in a function (let's call it ...
  • 1,663
5 votes
Accepted

Settings JAVA_HOME with Powershell

For a beginner script there are some There might be more to cover but there are a few things here that could improve the script. Variable and function naming In general functions and cmdlets should ...
  • 2,548
5 votes
Accepted

Normalize video filenames and move files to destination directory

Get-ChildItem -include *.ext1, *.ext2 instead of Where Use pipelining via | (in direct ...
  • 1,952
5 votes
Accepted

Arp-spoof check in PowerShell

split and spread to variables: $IP, $SubnetBits = $Subnet -split '/' your user-function invocation with parentheses is incorrect and works only for single ...
  • 1,952
5 votes
Accepted

Powershell script to verify Linux-generated md5sum file

here are a few changes i would make. [grin] the ideas ... use Get-Content instead of ReadLines() the speed difference is not ...
4 votes
Accepted

Terminating an Active Directory user

Prompting for confirmation The way you're doing the prompt is overly complicated. Consider this: ...
  • 1,769
4 votes

Delete folder if it exists in PowerShell

This will delete an empty folder as well and still propagates errors if files cannot be deleted ...
  • 141
4 votes
Accepted

Powershell photo sorter/mover

Write-Host("Great!") You should omit the parentheses here and just do: Write-Host "Great!" Using parentheses (and ...
  • 1,769

Only top scored, non community-wiki answers of a minimum length are eligible