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
3 votes
1 answer
322 views

Cleanly setting ACLs

So this is my full script that I've been working on. My plan is to Create New, Folder, Create AD Group FS-TESTSHARE-R, Create AD Group FS-TESTSHARE-RW, Apply Both groups to the new share folder, Set ...
Shane Johnson's user avatar
2 votes
1 answer
623 views

Powershell task to poll SQL database for psexec commands to run

We have a requirement for a script which polls an SQL database for scrape commands which need to be run. These commands are added to the SQL database on an ad-hoc basis. The scrape commands themselves ...
kafka's user avatar
  • 426
10 votes
1 answer
1k views

Batch script to make folders hidden

I just wrote a simple script cmd to hide private folders by combining several scripts from the Internet. Can anyone give me suggestions for improvement? This batch file uses a password hidden by ...
Muthiullah's user avatar
10 votes
1 answer
2k views

Powershell Script for setting DHCP reservation description & host value

I'm new to Powershell scripting and trying to write a script that will go through printer queues on a print server, get the print queue's port address, then compare the print queues port address to ...
BrodieFrankfurt's user avatar
4 votes
1 answer
137 views

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

Not sure how to make the title smaller. I was reading the question A truly amazing way of making the number 2016 and some of the answers referred to programatically determining the answer set. What ...
Matt's user avatar
  • 2,558
10 votes
1 answer
148 views

Bush wanderer console game

I had read the question: Bush Wanderer - code intended for teaching and wanted to play with PowerShell. Including the rules of the game from that same question. Bush Wanderer Task 1 ...
Matt's user avatar
  • 2,558
4 votes
1 answer
4k views

Get AD Users' Latest Last Logon Dates across Multiple DCs

I was recently asked to help our Spanish BU to audit their AD for inactive accounts. Grabbing a script from online I gave them this: https://gallery.technet.microsoft.com/scriptcenter/Get-Active-...
JohnLBevan's user avatar
  • 1,409
7 votes
2 answers
1k views

Power-Guessing The Number

I decided to help @Matt out a bit and ask a PowerShell question. This is a simple guess-the-number game learning how to use functions with and without parameters, and use the input and output ...
user avatar
6 votes
1 answer
155 views

Sherlock is going against the Beast with PowerShell

I ran into this challenge a couple of times today and thought I could tackle it with PowerShell. I refused to look at other peoples approaches to this hoping to complete it on my own. I'm sure the ...
Matt's user avatar
  • 2,558
3 votes
0 answers
70 views

Non-install based customization for creating windows 7 images

Before I had access to VM's, money or had any PowerShell knowledge I made this script that would do some image customizations for me. I used physical computers and would be reinstalling the OS while I ...
Matt's user avatar
  • 2,558
5 votes
1 answer
478 views

Find related groups among list of users

I have one of my first PowerShell scripts that will query a list of users in Active Directory. While doing so it will keep a tally in a hashtable that will update for every group increasing it count ...
Matt's user avatar
  • 2,558
2 votes
2 answers
1k views

Powershell script to iterate through folder and restore SQL backups

I am working on a PowerShell script which will loop through a directory containing SQL Server database backup .bak files; move the files to a different location; restore each of those files to the ...
kafka's user avatar
  • 426
2 votes
1 answer
922 views

Creating a portable encrypted credential store

There have been a few questions over on SO recently about securely storing credentials in Powershell scripts. Because ConvertFrom-SecureString uses DPAPI it makes ...
Michael B's user avatar
  • 123
6 votes
1 answer
193 views

SharePoint Online inventory

I'm creating a script to turn into a commandlet we can reuse as part of our custom PowerShell module. This works, but is very slow. I don't suspect it is anything to do with my code. I have to ...
Eric Alexander's user avatar
3 votes
1 answer
1k views

Delete orphaned SIDS + change to full control

I need to delete all the orphaned SIDs in the ACLs of about 20 shares (between 100GB/6TB) and change full control of users groups to other permissions (modify or read/execute). I have done this script ...
user5502079's user avatar
5 votes
1 answer
5k views

Batch/PowerShell script that toggles the minimized state of a window

I wrote this script for a user who wants to toggle the minimized state of a window that minimizes to the tray. The user required a .bat script, so I wrote a bat + PowerShell hybrid script in order to ...
rojo's user avatar
  • 378
11 votes
1 answer
1k views

FizzBuzz: A PowerShell Story

After reading way too much into what fizzbuzz was I though PowerShell could easily have its way with this. ...
Matt's user avatar
  • 2,558
5 votes
1 answer
3k views

Query AD and build CSV based on certain user object properties

My question is about code efficiency. I recently had to write a Powershell 3.0 script which had the following criteria: It had to pull all enabled user objects from active directory It had to pull ...
user avatar
1 vote
1 answer
1k views

XML editing and merging

I have only started working with XML files and PowerShell. I feel that while there are many ways to accomplish the same thing that I might be doing the following inefficiently. This is all based on ...
Matt's user avatar
  • 2,558
5 votes
1 answer
3k views

Powershell zip subfolders recursively, conditionally

This is a progression of the script I posted here: Zip the contents of subfolders, conditionally It does this: Determines all subfolders recursively Checks each subfolder for files older than 31 ...
Charon's user avatar
  • 289
5 votes
1 answer
450 views

Powershell to break apart large flat files (e.g. csv)

I created the below script to help break apart large flat files; to save myself effort opening files which are several gigs in a text editor and manually split them. So far I've only tested on sample ...
JohnLBevan's user avatar
  • 1,409
4 votes
1 answer
85 views

Enforcing Paired Statements Using ScriptBlock

I really like c#'s Using statement as it allows you to pair Open statements with their corresponding ...
JohnLBevan's user avatar
  • 1,409
3 votes
2 answers
606 views

Oneliner to extract External IP from IFCONFIG.CO

I wrote a small function in powershell that works fine, however I feel its extremely hacky and I'm sure there must be a smarter way to do this. In the interests of learning, what can I do to improve ...
Patrick's user avatar
  • 133
3 votes
1 answer
2k views

Zip the contents of subfolders, conditionally

I've written a script in Powershell for zipping files into new folders. This script performs the following steps: Check whether each subfolder contains non-zip files which are older than 31 days If ...
Charon's user avatar
  • 289
4 votes
0 answers
867 views

PowerShell GUI to display information about users

I have a GUI file which is currently being ran by VBS, but I have a few issues: PowerShell v2 is what is being run on every machine and I cant change that, runs very slow on first time launch. it ...
Visar Baci's user avatar
4 votes
2 answers
2k views

Powershell function to get hash value of a file

I created a function to get the hash value of a file. Normally the output is 3 lines. My function does 3 things: extracts the hash value removes the spaces in between the hash value prints hash ...
jes516's user avatar
  • 255
5 votes
1 answer
364 views

Querying list of servers with PS to report on Scheduled Tasks

I work in a Windows environment where Scheduled Tasks have never been documented or kept up with, leaving us with about 150 servers that have a random smattering of tasks. I am attempting to construct ...
user3029809's user avatar
5 votes
1 answer
337 views

Terminating an Active Directory user

I'm writing an AD Termination script for work. I'm new to PowerShell and was wondering if multiple commands within PowerShell switch statement is okay to do: ...
MFonner's user avatar
  • 53
2 votes
1 answer
12k views

Powershell to Convert HTML Table to Array of PSCustomObject

I created the below script to sent a request to a website, then convert the table in the results to an array of PSObjects which I can work with in PowerShell. This uses some nasty hacks (e.g. using a ...
JohnLBevan's user avatar
  • 1,409
1 vote
1 answer
2k views

Tree-view of Active Directory group memberships using recursion

Using Powershell, I've created a script to create a tree-view of a group/s' memberships in Active Directory. I originally had layers of nested loops, but I wanted a more algorithmic solution. The ...
Jarom's user avatar
  • 37
25 votes
1 answer
4k views

Powershell to quickly ping a number of machines

I came up with the below code to improve the peformance of pinging a large number of machines. At present it's fairly basic, but thought I should see what people thought before proceeding further. NB:...
JohnLBevan's user avatar
  • 1,409
3 votes
1 answer
810 views

PowerShell Unpivot Object

Based on a question on SO I thought I'd knock up a cmdlet to perform an unpivot on an object. I've not yet considered all the options (e.g. what happens when objects with empty lists are passed), so ...
JohnLBevan's user avatar
  • 1,409
7 votes
1 answer
1k views

Import Excel, unpivot data, output tab-delimited for SQL Import

I have a client GL file (Excel) that needs to be regularly imported to SQL Server (as tab-delimited txt). Sample (simplified): ...
Matt's user avatar
  • 215
66 votes
3 answers
109k views

Delete folder if it exists in PowerShell

In my PowerShell script I'm trying to delete a folder, but only if it exists: if (Test-Path $folder) { Remove-Item $folder -Recurse; } I find myself repeating ...
Jeroen's user avatar
  • 1,441
4 votes
1 answer
1k views

Getting a list of all computer objects in each AD domain

So I wrote this script and although it does work I can't help but think that it can be more efficient with all the repetitive code. Can anyone offer any suggestions on making it fewer lines and ...
JoeRod's user avatar
  • 141
4 votes
1 answer
292 views

Powershell photo sorter/mover

I'm just beginning in Powershell - This will be my first full project, start to finish, and it's quite small. I have already had experience in C#, which helps in this .Net based language. This ...
Cullub's user avatar
  • 185
3 votes
1 answer
6k views

Convert list of UTC to Current TimeZone

I found myself with a list of UTC timestamps and wanted to convert them into the local time zone. Using this web post as a starting point, I modified the script to grab a text file containing UTC ...
user4317867's user avatar
10 votes
1 answer
3k views

MD5 hash comparison for two folders

Using this page for a starting point into comparing MD5 hash values from files in two different folders, I've put something together that outputs either Copied if ...
user4317867's user avatar
-2 votes
1 answer
466 views

Extracting first initial and last name [closed]

How can I do this better? $a = "Tom Smith" ; $e = $a.substring(0,1) $ee = ($a).split(" "); $y = $e + $ee[1]; $y TSmith
CUDY's user avatar
  • 9
8 votes
1 answer
7k views

PowerShell within HTA

I've put some code together that helps me search an internal ticket system using an HTA application with some TextBoxes and some embedded VBScript that runs PowerShell scripts. The PowerShell scripts ...
user4317867's user avatar
1 vote
1 answer
2k views

Write to the event log without needing to check whether or not it exists by use of a `-Force` parameter

Below is some powershell to write to the event log; if the -Force parameter is specified this saves you the effort of writing additional code to first check whether ...
JohnLBevan's user avatar
  • 1,409
4 votes
1 answer
145 views

Backing up single-user PC data

I wrote a PS script to backup data from single user pcs to their network homedrive. The purpose of this tool is to save some time and ensure process consistency when reimaging/replacing machines. I ...
Josh Pratt's user avatar
11 votes
2 answers
22k views

Powershell search millions of files as fast as possible

I once asked a similar question but in C#. Now I have the same problem in powershell.. What is the fastest way, to search files newer than 15 minutes, in a file system with more than 1 million files? ...
greenhoorn's user avatar
5 votes
3 answers
8k views

Powershell script to create folders on remote servers

This is pretty much the first Powershell script I've ever done and I am here looking for a quick review of it. Is there something I could have done better? Is the format okay? I don't know much about ...
user3029809's user avatar
4 votes
1 answer
97 views

Recycling Internet Explorer

Is there anything I can do to this code to optimize it to use less resources? ...
GiantDuck's user avatar
  • 141
5 votes
2 answers
391 views

Getting essential computer info for network admins

I recently had to install VNC on mass across a lot of computers on a domain and needed some info about their PC, for example: Host name Username MAC Address IPv4 Address Domain name Once all of this ...
Phasmatis's user avatar
7 votes
1 answer
3k views

Active directory password changer

I have written this Active Directory password changer script. Comments and testing is appreciated for things I may have overlooked, since this is my first AD Script. There are two parts: PHP and ...
Werezwolf's user avatar
9 votes
1 answer
875 views

Powershell Windows Service Deployment

Based on this with a couple of changes. Any issues you can point out would be great. param([string]$targetServer, [string]$user, [string]$pass) ...
thedev's user avatar
  • 827
2 votes
1 answer
1k views

AD update from CSV

I get a CSV dump of all employee records from our payroll system once a week. The CSV has something like 28K records. The key between the two systems is the ...
user3931089's user avatar
3 votes
1 answer
807 views

Adding file name information to CSV file columns

Is there a simple way to combine the functions of this Powershell script? It would be nice to have it file to one output file instead of several output files. ...
Jerry Sweeton's user avatar