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
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 ...
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 ...
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 ...
5
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 ... ...
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
...
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 ...
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 ...
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 <...
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.
...
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 ...
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 ...
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, ...
4
votes
Accepted
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 ...
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):
...
3
votes
Replicate / Sync files from source to destination with powershell only
Frankly, robocopy.exe is such a good tool for this job and has been a part of the base Windows install since Vista/2008 that I would just use that instead of ...
3
votes
Accepted
Work with configuration files holding encrypted credentials
One of the main problems here I think is that the encrypted version of the password can only be decrypted by the account who ran the unencrypted configuration first, on the same computer.
Your ...
3
votes
Accepted
Powershell Script to remove printers and drivers
Before relying on old VBS scripts, it pays to check what native PowerShell tools you have available:
...
3
votes
Accepted
Clearing files from directories
There's an important principal in programming called Don't Repeat Yourself (or DRY). This says that if there is any repeated code, then that is usually a bad thing. So let's identify the non-repeated ...
3
votes
Accepted
Powershell script to save user credentials in a xml file
Instead of letting the user (1) choose a folder and (2) choose a file name, you can just present the user with a Save File Dialog. It also warns the user if he tries to overwrite an existing file.
If ...
3
votes
Script to backup data to specific USB Drive
Get-WmiObject has been superceded by Get-CimInstance since PowerShell 3 and removed since PowerShell 6, so you should avoid ...
3
votes
Accepted
Read SIDs and set ACLs
nope! [grin]
this is almost entirely about style, not performance. you will note that most points are about readability ... the following line is quite true ...
better readability gives ...
3
votes
What's a better way to decrease cardinality when serializing records
You can use XElement.
It is especially useful when constructing XML.
...
3
votes
Accepted
Get username from full name - PowerShell function
i think the comments cover the why of things, but please feel free to ask if you have any questions. [grin]
...
3
votes
PowerShell - fast remove a directory with 10,000+ files
The foreach-object is not run in parallel by default.
You need specify the -Parallel parameter. And the version of Powershell ...
3
votes
Accepted
Creating a specific distribution of random numbers in Powershell
Since you tagged your question with Performance, my example is not totally idiomatic PowerShell.
You could build a lookup array with each number as many times as ...
3
votes
Disk usage reporting script performing poorly with lots of files
Your primary performance problem is due to this pattern:
$Set = 1..10000
$Array = @()
foreach ($i in $Set) { $Array += $i }
This is an awful pattern whether you're ...
3
votes
Accepted
Powershell script to check for processes on remote systems and rename/copy files
In a high level language one could write it even more terse and save a bit on repetitive code. Gramatical ... and-then ... and-then .... Collecting ...
3
votes
Accepted
Powershell script that directly executes python script
The two things that jumped out at me are the wall of calls to Write-Host that can be cleaned up using Here-Strings, and how you are implementing the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
powershell × 265performance × 35
beginner × 35
csv × 25
windows × 24
active-directory × 21
file-system × 19
programming-challenge × 8
excel × 8
strings × 7
logging × 7
c# × 6
file × 6
installer × 6
object-oriented × 5
time-limit-exceeded × 5
console × 5
batch × 5
sql × 4
sorting × 4
recursion × 4
comparative-review × 4
regex × 4
security × 4
converting × 4