Category Archives: powershell

Disable rogue domain computers with Powershell

Ever find out that there’s employee’s insist on adding computer to your company’s domain? Hate having to manually check every once in a while for new machines? Fret no more! Here’s a simple script that will simply disable the computer accounts!

#
# disable unauthorized computers
#

## Create the AD object for looping through.
$root = New-Object DirectoryServices.DirectoryEntry “LDAP://CN=Computers,DC=domain,DC=com”

$selector = [...]

Learning the nuances of Visual Studio

I’m starting to use Visual Studio and programming more and more in C#. Mostly this is because I’m finding that creating tools with scripts for my end users to be too cumbersome for them to use. PowerShell scripts are not easily launched by a double click, you need to allow scripts in the first place [...]

Scripted forms

I’ve known using Windows.Forms with Powershell for some time, but never really dove into it until recently. One of the reasons for this is that I don’t like the idea of making tools that can’t be picked apart by others in my department. Another reason is that unless your form is just to make the [...]

Change file creation/modify/last accessed time

Question: How many lines does it take to change a file’s creation, modified or last accessed time?
Answer: One Powershell line.

(ls \some\file.txt).CreationTime = (date(”Jan 1 1979 12:00:00 am”));
(ls \some\file.txt).LastWriteTime = (date(”Jan 1 1979 12:00:00 am”));
(ls \some\file.txt).LastAccessTime = (date(”Jan 1 1979 12:00:00 am”));

Creating a random password

Recently I was needing to create a bunch of random passwords for users and I needed to have it work in Powershell.
Since Lee Holmes’ comments, I’ve updated the file and function with some of the suggestions he gave. Unfortunately, the <# #> help syntax throws a bunch of errors in V1, so I had to [...]

Bootstrapping scripts

One of the problems here at work that we have is for some oddball reason people just can’t seem to get UNC paths to work right when it comes to DFS. For those cases we’ve had to resort to mapping these people directly to the server that is the primary location. Since these people are [...]

Unprotecting Word Documents

A quick search around Google reveals that there are many an application that will remove the protection from Word documents. However I question the trustworthiness of these programs, what if they install key loggers, or trojans, or some other nefarious code? So I did some research and scripting to make my own document cracker, and [...]

MergeXML

A recent project at work required me to merge two XML documents together and thus this was born, MergeXML. It’s written for Powershell and thus can be used for a variety of things. From a simple command line utility to an entire login script (which is why I need it).
MergeXML