Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Download File with a PowerShell One-Liner

I was recently trying to automate some scripts on a linux box and I wanted to know if it was as simple to download a file in PowerShell as it is in linux: wget http://example.com/file.jpg
Well as it turned out, it wasn’t, but it wasn’t that difficult either. What we needed was too use the System.Net.WebClient class. There’s one thing to note, in PowerShell you can’t use a ~ (tilde) to reference your home directly, that is to say, you can’t download a file to ~\Desktop you will need to specify the full path, in my case C:\Users\Brangle\Desktop. […]

Make PowerShell Talk / Speak

Have you ever run a long PowerShell script, minimized it, only to realize much later that an error caused it to stop? Rather than just using a color syntax red to display the error,  I wanted to hear it so I could switch back to the PowerShell window and see the error. So how easy is it to make PowerShell speak? It’s almost identical to the .NET code I have in VB.net and C# on Make Your Computer Talk with VB.NET Application (and Source Code) using the SAPI.SpVoice class. […]

Combine or Join Two Text Files Using PowerShell

Merging files together, or to a seperate file, is a snap with PowerShell using the Get-Content cmdlet. If you’ve never used the Add-Content cmdlet, I would suggest first reading my other article Append Text to a File Using Add-Content. The first thing we need to do is identify our two files, in my case I’ll be using file1.log and file2.log. In the first example, I append all the text of file2.log into the end of file1.log. In the second example, I’ll create a completely new file and dump the contents of both the files into the newly created file. In the last example, I’ll add the current date to the filename of a completly new log file. […]

Retrieve File Permissions using Get-Acl with PowerShell

Retrieving the owner and permissions of a file, folders and even registry keys is a breeze with PowerShell’s Get-Acl cmdlet. Let’s try checking to see who has access to to the C:\Documents and Settings\Administrator folder. […]

How to Ping a Computer using PowerShell

Pinging a computer is really simple, and of course since this is PowerShell we don’t want to just use something as primitive as ping.exe, we want to use .NET and take advantage of all the method calls and filters. […]

Using the System.Environment Class in PowerShell

The Environment class has a huge array of information and accessing this information is very simple, I’m going to try and give a whole bunch of one line examples of how to do this using PowerShell. […]

Send eMail and SMS Text Messages with PowerShell

Thanks to the .NET library sending emails with PowerShell is surprisingly very simple! One thing to remember is line breaks, when you need a new line, make sure to use the escape characters `n . In the first example, I’ll send just a regular email, in the second I’ll send a SMS text message. […]

Append Text to a File Using Add-Content in PowerShell

Here’s a quick tutorial on how to add text to the end of a text file using the Add-Content or its alias ac in PowerShell. In this first example let’s add "This is the last line" to the end of a file. […]

Pass Credentials via PowerShell

I’ve often found it necessary to pass my Administrator domain or Domain Admin (DomAdmin) credentials to run a PowerShell WMI command. Fortunately PowerShell provides 3 different ways of doing just that, not counting using Windows built in runas command. The three methods I’m going to go over are

  1. Entering your own unique credentials
  2. Entering a service account password, ie: the same username (or hard coding a username)
  3. Hard coding a user name and password

[…]

Mounting a Virtual/Network Drive with PowerShell

There’s multiple reasons why someone would want to mount a virtual or network drive, especially in an enterprise environment where many users don’t understand the concept of UNC paths or when older software doesn’t support long path names or UNC connections. Now there’s two things we need to know, is this a local path, or is it somewhere on the network. Once we know that we can get started. […]