Skip to main content

Questions tagged [powershell]

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices.

Filter by
Sorted by
Tagged with
1 vote
0 answers
563 views

PowerShell - Find Least Common Multiple of a series of numbers

I am a Windows power user, a system tweaker, my idol is Leanardo da Vinci, and now I want to be a hacker. I am extremely new to programming, but I really am a fast learner if I am interested in the ...
Ξένη Γήινος's user avatar
1 vote
0 answers
804 views

PowerShell - Calculating date difference between two given dates in days without builtin and with builtin

The title says it all, I have written two scripts to calculate dates to test my abilities in programming, one from scratch, without [DateTime], New-TimeSpan and even [math]::Ceiling, and it's really ...
Ξένη Γήινος's user avatar
1 vote
0 answers
136 views

Remote computer file transfer with PowerShell script

Remote-Computer-File-Transfer I have created a PowerShell script, , for remote computers file transfer, for computers that only support New-PSDrive cmdlet, and I ...
Zoran Jankov's user avatar
1 vote
1 answer
177 views

"Backwards Read Primes" of Codewars powershell version

Link to problem: https://www.codewars.com/kata/5539fecef69c483c5a000015/train/powershell I have a working solution in Codewars but my solution is slow for some reason and I need to improve the ...
Gringo Jaimes's user avatar
1 vote
0 answers
74 views

Weekly Employee Report Generator PowerShell Script

Weekly Employee Report Generator PowerShell Script Description This script is used for generating a Markdown template file for weekly employee reports. In ...
Zoran Jankov's user avatar
1 vote
1 answer
91 views

Fully parameterized PowerShell function for file removal

I would like your opinion on my Remove-Files PowerShell function. It is used in my File-Removal-PowerShell-Script. It is designed to be very flexible so a script ...
Zoran Jankov's user avatar
3 votes
0 answers
226 views

Get specific properties for all Active Directory groups and all their users, then combine them into CSV

I've written a script that gets a list of all groups in AD along with a few specific properties for each group (DistinguishedName, CN, Type, and Description). Then it goes through each group and, for ...
TylerH's user avatar
  • 131
3 votes
0 answers
871 views

PowerShell Script to get data from Third Party API and insert into database

I have created a PowerShell script that will call a REST API and then for each node returned, add the data into a database table. This particular endpoint only returns ~600 records worth of data, ...
Ross's user avatar
  • 327
3 votes
0 answers
310 views

Update AD Group based on CSV File

I have an AD Group I keep up-to-date based on a CSV file. Users not present in the file should be removed from the AD Group. ...
Peter9001's user avatar
4 votes
2 answers
147 views

Log writing PowerShell function

I am still learning PowerShell and I would like your opinion on my log writing function. It creates a log entry with timestamp and message passed thru a parameter Message or thru pipeline, and saves ...
Zoran Jankov's user avatar
2 votes
1 answer
68 views

Deploy folder to desired path - PowerShell function

I am still learning PowerShell and I would like your opinion on my folder deployment PowerShell function. It basically check if a defined folder exists and creates it if it does not and writes it ...
Zoran Jankov's user avatar
2 votes
0 answers
146 views

PowerShell Script to Harvest System Inventory

I've written a 'fast & dirty' PowerShell script to harvest a system inventory of Windows client and\or server operating systems to streamline case note documentation. ...
Pendraig's user avatar
5 votes
2 answers
921 views

Get username from full name - PowerShell function

I would like your opinion of my PowerShell function. Does it follow conventions, and what could can I do to improve it. It is made to create LDAP friendly username from a full name in Serbian language....
Zoran Jankov's user avatar
7 votes
1 answer
708 views

Powershell script to verify Linux-generated md5sum file

I'm moving some files from a Linux machine to a Windows machine over a low-speed, possibly buggy experimental communications channel that I want to test. One of the tests is to transfer large numbers ...
Edward's user avatar
  • 66.5k
1 vote
0 answers
234 views

File Deletion PowerShell Script

I would like your opinion of my PowerShell script for file deletion. Do I follow conventions, do I use some anti patterns? Every critique is welcome! This is an example of a report log: This is the ...
Zoran Jankov's user avatar
4 votes
2 answers
198 views

Powershell XML search performance

I am working on a utility to manage shared content libraries for Work from Home scenarios. Basically I have libraries of thousands of Autodesk Revit family files, and I want to host those files on AWS ...
Gordon in Ukraine's user avatar
3 votes
2 answers
714 views

Smartly joining possibly empty strings

I want to join two fragments into one string with a separator, but when one of the fragments is empty I only want one of them. I have two implementations. The first is long and slightly repetitive, ...
schuelermine's user avatar
4 votes
1 answer
2k views

Converting JSON to CSV using powershell

I have a very large JSON Lines File with 4.000.000 Rows, and I need to convert several events from every row. The resulted CSV File contains 15.000.000 rows. How can I optimize this script? I'm using ...
user avatar
4 votes
0 answers
61 views

Add VMs and corresponding replications to VMGroups in a Hyper-V cluster

I'm looking for input on how to improve a powershell script I wrote. Im especially looking for suggestions, that I might be able to apply to future projects as well. Like (anti-)patterns I'm not aware ...
geets's user avatar
  • 41
1 vote
0 answers
40 views

Satisfying general rate limits in PowerShell

I wrote this code for a PowerShell function that allows you to specify rate limits and makes a script block follow those limits. The script block return value is for specifying if it should be ...
schuelermine's user avatar
2 votes
0 answers
1k views

Powershell custom exception class

I am trying to get my head around exceptions, and implement exception handling that ultimately gets logged, since my code runs as a remote job and reviewing a txt log is the best means of reviewing ...
Gordon in Ukraine's user avatar
2 votes
0 answers
26 views

I am gathering all the Azure subnets for Central US and trying to filter out the smaller subnets that are part of the larger... Very slow

The goal of this code is to remove subnets from the list that are redundant (included in the larger ones) It is VERY slow. Wondering how it can be sped up. At present, I’m not looking to optimize ...
dragonspeed's user avatar
2 votes
1 answer
97 views

Removing contact from all mail groups

I want to remove the mail contact from all Groups in the "Member Of" tab. I am able to remove all MemberOf for mail contact. How can I improve the speed of the script? ...
Cell-o's user avatar
  • 295
3 votes
1 answer
330 views

Enum in PowerShell Class

I am playing with learning PowerShell classes, and I have a validation situation that kind of lends itself to Enums, as shown in the first example. With Enum ...
Gordon in Ukraine's user avatar
3 votes
1 answer
85 views

What's a better way to decrease cardinality when serializing records

I need to transfer data from one vendor's system to another. The source vendor has a view that generates data that combines invoice and line-item data into records w/ line-item cardinality: ...
craig's user avatar
  • 173
3 votes
1 answer
876 views

Is this powershell code to install the linux sl command to PowerShell good?

I have the following code in my project that installs linux sl on Windows using PowerShell. Is there anything you'd improve about this? ...
schuelermine's user avatar
2 votes
1 answer
139 views

Read SIDs and set ACLs

The following script reads a set of SIDs inside firewall rules and uses them to set ACL rules in a folder. The question is: Is this syntax ok or is there better ways to write this script, considering ...
Dennes Torres's user avatar
4 votes
0 answers
141 views

downloading a list of urls

I wrote this quick (lots of googling) and dirty (I hope not too dirty) script to download a URL list with a win32 wget port and save them as files with the url as the name to use as a "poor man's url ...
beppe9000's user avatar
  • 191
3 votes
1 answer
79 views

Function to class migration: constructor best practice

I am working on moving some complex script logging from functions to classes. In the functional version I would use a string like this ...
Gordon's user avatar
  • 131
4 votes
1 answer
54 views

Duplicated lines easier to read vs DRY

Please see the file here, reproduced below in separate sections. My question is basically Which way is better? Which is easier to understand? Which is easier to modify? What should be the priority?...
Vijay's user avatar
  • 141
4 votes
0 answers
86 views

Powershell optimization (scripts to run simultaneously)

I need some help here, I posted on stackoverflow and was directed here, just to put things in context, I am new to PowerShell, I have a task, that in simple terms, would take a csv with more than ...
Roi Samagoue's user avatar
3 votes
2 answers
154 views

PowerShell script creates a computer list from an AD OU, and add exclusions to a specific file via Invoke-Command

My code is working, however, in the foreach section, when it runs the invoke-command if I don't use "-ErrorAction SilentlyContinue" the red error text that states a computer cannot be connected to ...
xerxes2985's user avatar
3 votes
0 answers
97 views

PowerShell script to execute Docker maintenance, optionally non-interactively

Problem Developers in my team are new to Docker. I wanted to provide a way to accomplish general Docker housekeeping tasks (like pruning unused images and compacting the Hyper-V volume) largely ...
msanford's user avatar
  • 391
4 votes
0 answers
182 views

Powershell: does a file name contain a value

I need to check if a filename contains a value that I get from 2 excel Columns (ContractNumber & PONumber). My Script is too slow right now. It has been running for 1 hour, and it completed only 2%...
Macinar's user avatar
  • 41
3 votes
1 answer
1k views

Powershell script to stop and start services on demand

The purpose of below code is to stop/start a couple of windows services if they are running/not running, this will be called from a windows command line. The services could be either on a windows ...
ZeExplorer's user avatar
6 votes
1 answer
925 views

How could I have made this Powershell script that executes robocopy code better

I am trying to get better at Powershell and was wondering if I could get some advice on how to make this code more efficient/cleaner/anything. This code is intended to launch three batch windows ...
Bee's user avatar
  • 63
4 votes
1 answer
429 views

Script to backup data to specific USB Drive

I have a script and I was looking to have it reviewed to see where I should improve it. Our need: We need to backup a folder every day to a specific USB drive. There may be multiple USB drives ...
RookieUser's user avatar
2 votes
0 answers
59 views

Add and toggle firewall rule and change DNS settings

I have been working on writing a script that will allow me (and my wife, as you'll see in some of the text in the code) to switch countries for some streaming services I use. It first checks to see ...
Iceape's user avatar
  • 315
2 votes
1 answer
52 views

Script to Backup Data to Remote Location. The data to backup depends on the day of the week

I have a script that I wrote, and I'm sure that there is a better way to do it, but can't for the life of me figure it out. Here is the problem statement: I need to backup data to a remote location, ...
Harlan's user avatar
  • 63
4 votes
1 answer
221 views

Powershell - Simplified Logging

Today I have dealt with logging in PowerShell as well as with the different streams and the pipeline. Unfortunately, none of these solutions really met my needs. My requirements are: I need to ...
kami's user avatar
  • 41
1 vote
1 answer
46 views

Check multiple subdirectories and delete if file exists [closed]

Long story short, I have over 180K files that I need to delete. I have all of the file names that need to be deleted in a TXT file, however the files that need deleting are scattered in over 400 ...
AuXDubz's user avatar
  • 11
4 votes
1 answer
4k views

Creating a file of md5 hashes for all files in a directory in PowerShell

I have been trying to write the md5 hashes for all files in a directory and its subdirectories to a file. Ideally, replicating the output of the Unix command ...
Stacey's user avatar
  • 41
2 votes
0 answers
84 views

Powershell script to find and replace words based on asset tag input

Can someone please help me modify this script to generate and modify the document faster? It currently takes about 5-10 seconds to create the variables. About 10 seconds for the entire script to run. ...
Dil Pat's user avatar
  • 21
2 votes
1 answer
1k views

Create a csv of file attributes recursively from a directory parameter in PowerShell

I'm a bit new to PowerShell (version 5) and was wondering if there are any improvements I could make to the following script. Any suggestions for style, code, etc. are all welcome. The script creates ...
aduguid's user avatar
  • 490
-1 votes
1 answer
634 views

Huge performance difference: PowerShell Core vs. 5.1 [closed]

Recently I have answered another question about performance. A solution found using PowerShell-ISE successfully, and good speed testified using PowerShell Core. However, running the same script(s) in ...
JosefZ's user avatar
  • 494
2 votes
1 answer
4k views

PowerShell - Loop Through Nested Objects

I'm writing a PowerShell script to loop through an organization's PowerBI workspaces and spit out the report IDs, names, and URLs for each workspace - so, a nested loop. Here's my working script thus ...
Kyle Hale's user avatar
  • 820
4 votes
0 answers
111 views

Sorted LinkedList

A linked list is a data structure that has a beginning, and an end. The only way through the structure is to go to the "next step", like stepping stones. This linked list works the same way, but in ...
KGlasier's user avatar
  • 141
3 votes
1 answer
95 views

Removing duplicate audio files with different UTC timestamps in filenames, using PowerShell 5

I have a drive with many thousands of sound effects. The files have been stored on different operating systems and NAS devices over time and there are now duplicates of many files, but the filenames ...
Yosemite's user avatar
  • 137
2 votes
1 answer
63 views

Combine Medical Response Files Prior To Table Load

This is a script I wrote to: Combine multiple text files into one CSV Append the source file's name to each line of data This script currently takes about 3 seconds per 10,000 lines read - this is ...
user avatar
4 votes
0 answers
597 views

ASCII-Box PowerShell menu

I've written a pair of functions that can be added to a module or script that will allow the developer to specify a list of options and let the user select with the up/down arrow and return any ...
Rich Moss's user avatar
  • 239