Skip to main content
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
Max's user avatar
  • 81
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 ...
Dangph's user avatar
  • 1,683
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 ...
Bruno Costa's user avatar
  • 5,566
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 ...
Dangph's user avatar
  • 1,683
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 ...
Dangph's user avatar
  • 1,683
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: ...
Ansgar Wiechers's user avatar
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 ...
Matt's user avatar
  • 2,558
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 ...
Matt's user avatar
  • 2,558
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 ...
woxxom's user avatar
  • 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 ...
woxxom's user avatar
  • 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 ...
Lee_Dailey's user avatar
5 votes

PowerShell - fast remove a directory with 10,000+ files

As pointed out in a comment from @Lee_Daily, reinventing the wheel from an interpreted language like PowerShell will be slower than a native implementation. If your primary concern is speed, use the ...
HackSlash's user avatar
  • 382
4 votes
Accepted

Grouping all mathematical results using a number sequence with basic math operators

About performance (there's a good article to get your started: Slow Code: Top 5 ways to make your Powershell scripts run faster); I apply that advice as follows: Problem #1: Expensive operations ...
JosefZ's user avatar
  • 494
4 votes
Accepted

Bush wanderer console game

I like it, I learnt a few things about objects from this. I also really liked the board size can be easily changed. Immediate Collision When playing I noticed the Dragon was allowed to start in the ...
xXhRQ8sD2L7Z's user avatar
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 ...
arberg's user avatar
  • 141
4 votes
Accepted

Adding some properties to an Active Directory user

I think that's fine. The dot operator is an operator like any other, so you can line it up if you think that will improve readability. It's particular useful for "fluent" style method calls: ...
Dangph's user avatar
  • 1,683
4 votes
Accepted

Getting NTFS permissions of all shared folders on the local machine

The only way to improve the speed of the script is to drop the usage of Excel as a COM-object altogether. It is considered bad practice. And it is not possible on servers where Excel is not installed. ...
Adamar's user avatar
  • 246
4 votes

Using Powershell to Copy Files to Several Locations

Simple program at first glance. I am glad to see some documentation there that explains what the code does. This is a good and important practice. Set-Location This is the only real problem I see ...
Matt's user avatar
  • 2,558
4 votes
Accepted

Batch convert txt files to xls

As far as performance goes there are two general approaches to address this Parallel processing Running the com object is dragging in itself. Processing 10's of 1000's of files with one Excel instance ...
Matt's user avatar
  • 2,558
4 votes
Accepted

Reading event logs of several computers

Basics Aliases PowerShell is meant to be both shell and programming language. As such, it has a concept of Aliases. An Alias is another name for a command. An alias can resolve to a cmdlet, a ...
briantist's user avatar
  • 1,799
4 votes
Accepted

Comparing dates with SharePoint PnP PowerShell

I think it's okay, but we can do better. Let's see what Get-Date returns. Run this: > get-date | get-member It shows that <...
Dangph's user avatar
  • 1,683
4 votes
Accepted

Using PowerShell to deploy a staging environment to production

Just some random notes. Your code seems pretty good to me in general. ...
Dangph's user avatar
  • 1,683
4 votes
Accepted

Inserting data into SQL-Server table dynamically

The main problem with this code is that it's not screening column values, unfortuantely buit in mechanisms in Invoke-SQLCMD aren't viable. It allows to use ...
Bogdan Mart's user avatar
4 votes
Accepted

Determine the third octet of an IP address based on user entered site number

Let's start with a table of inputs and outputs, because it may not be exactly the same as what you expect from your script. The first column is the input range, the other column is the transformation ...
Oh My Goodness's user avatar
4 votes
Accepted

Deploy folder to desired path - PowerShell function

The code is very cleanly written, and its easy to see what is going on. The verb you are using for the command is not officially 'supported'. Every command should stick to the official list of verbs, ...
Withholm's user avatar
4 votes

Any issue with this as a password generator?

Your code looks quite neatly done. I would likely make a few changes: make the number of words to use a parameter [with a default value]. 3 is a good starting point, but folks may want 4 or more ... ...
Lee_Dailey's user avatar
4 votes
Accepted

Fetch specific data from nested JSON-file, then append it to a CSV-file

Date conversion ...
ojdo's user avatar
  • 420
4 votes
Accepted

Powershell Export function to create environment variables with bash syntax

The PowerShell-idiomatic approach is to: Define a command (function) that adheres to PowerShell's <verb>-<noun> naming convention, using one of the ...
mklement0's user avatar
  • 156
4 votes

Find all unique file owners through Powershell in an NTFS file system

If you only care about the unique file owners (not the count), something like (not fully fleshed out but to give you an idea): ...
Bangaio's user avatar
  • 41
3 votes

powershell md5 compare too slow

There are two obvious optimisations. The first is to remove the line $file_dest = Get-ChildItem -PATH $COMP_DEST -name since ...
Peter Taylor's user avatar
  • 24.1k

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