Powershell and Unicode

Oct 23 2012

I’m writing a Powershell script that creates an FTP script and then runs the FTP command using that script. The file created fine and the FTP command ran but the FTP script did not work:
$exportDirectory = “\\server\share”
$file= “$exportDirectory\test.txt”

function FTP-File($FTPusername, $FTPpassword, $FTPfile){
      “open” > $exportDirectory\ftp.scr
      $FTPusername >> $exportDirectory\ftp.scr
      $FTPpassword >> $exportDirectory\ftp.scr
      “put $FTPfile” >> $exportDirectory\ftp.scr
      “quit” >> $exportDirectory\ftp.scr
      ftp.exe -s:$exportDirectory\ftp.scr

FTP-File “username” “password” $file

FTP error
After struggling with it for a few minutes I realized it might be a file encoding problem. That weird character on the first line seemed to point to that. I looked and the ftp.scr file was encoded as “UCS-2 Little Endian” — well that’s an odd format. Outside of the script I change the encoding of that file to ANSI and ran the FTP command and it worked perfectly.
So Powershell file redirection creates Unicode files and the command line does not understand Unicode. The fix? Use Out-File instead.
function FTP-File($FTPusername, $FTPpassword, $FTPfile){
      “open” | Out-File $exportDirectory\ftp.scr -Encoding ASCII
      $FTPusername | Out-File $exportDirectory\ftp.scr -Encoding ASCII -Append
      $FTPpassword | Out-File $exportDirectory\ftp.scr -Encoding ASCII -Append
      “put “ + $FTPfile | Out-File $exportDirectory\ftp.scr -Encoding ASCII -Append
      “quit” | Out-File $exportDirectory\ftp.scr -Encoding ASCII -Append
      ftp.exe -s:$exportDirectory\ftp.scr
      Remove-Item $exportDirectory\ftp.scr

No responses yet

Watch Youtube Videos At A Faster Speed

Jun 22 2012

I’m currently going through the Udacity CS101 course. Much of the material I’ve already seen before in other languages but I don’t want to miss the Python specific information. Usually, in this situation, it feels like the video takes FOREVER to get through.

I’ve used VLC to watch downloaded videos at a faster speed (1.5x or 2.0x) but haven’t found anything that will do the same for streaming Youtube videos. Finally today I found it.

First, you have to opt-in to the HTML5 beta for Youtube. HTML5 gives you an alternative to Flash videos. It doesn’t work for all Youtube videos yet, but I haven’t run into any that it doesn’t work on. You can opt-in here: http://www.youtube.com/html5

After you’ve done that, the next video you load will have some extra options if the video supports it. Click on the gear and you should see some speed options to use. MUCH better!

HTML5 Youtube Settings

3 responses so far

Help! I Can’t Find This User To Add Them to an Active Directory Group!

May 30 2012

I ran into an issue at work where we couldn’t add a user to a local computer group. I later determined that you couldn’t find the user anytime you had to use the “Select Users, Contacts, Computers …” search window, like when you add the user to an AD group.


You could, however, find the user in the “Find Users, Contacts, and Groups” search box in ADUC.

I used a Powershell command to output the properties of the user account to a text file. I did the same thing for another non-problematic account. Then I used Beyond Compare to compare them. I found that the showInAdvancedViewOnly attribute was set to TRUE on the problem account and FALSE on the non-problem account.

Import-Module ActiveDirectory
 Get-ADUser ProblemUser -Properties * | fl c:\temp\problemuser.txt

I changed the value of showInAdvancedViewOnly to FALSE and now I can find the account and add it to groups.

One response so far

Microsoft Log Parser: Coolest Thing Since Sliced Bread

Aug 09 2011

I just stumbled upon a utility today that is going to save me a LOT of time — Microsoft Log Parser 2.2.

The past week has presented me with two different problems that I knew a SQL query would solve but my data was in text files and I wanted to keep it that way. I’m still a SQL newbie; I can write some queries to squeeze out the information I need but thats about it.

Let’s try MS Query

The first problem involved one text file with directory names and sizes. The second text file was a list of users with both username and userid as fields. I needed to find out which directories matched up with userid’s.

I found the MS Query* tool included with Office. Supposedly you can use it to treat both text files and Excel files as databases using SQL queries. I could never get it to work right for either file type. I shelved the problem for later.

That Didn’t Work, Now What?

On to the next puzzle. We have a field called employeeID added to the schema of Active Directory. I needed to find all accounts that have duplicate employeeID’s. I knew I could do this with a SQL query. I already had a CSV file containing a dump of several AD attributes for all users. I planned on importing the CSV file into a SQL table and working with it. In searching to figure out how to build the query, I found Log Parser.

Log Parser is a utility written by Microsoft originally to parse IIS logs. It does that and much, much more. It will parse just about any structured text file, the event log,  the file system, and the registry. It’s not a supported utility but this site has an active user community.

I was able to use this command to pull up a nice GUI table format:

logparser file:myquery.sql -i:csv -o:datagrid
Log Parser Datagrid View

Log Parser Datagrid View

This command exported the same information to a CSV file:

logparser file:myquery.sql -i:csv -o:CSV
-headers:ON > duplicate-employeeid.csv


My myquery.sql file looked like this:

SELECT employeeID,sAMAccountName,sn,givenName
FROM 'users.csv'
WHERE employeeID IN
  (SELECT employeeID
  FROM 'users.csv'
  GROUP BY employeeID
  HAVING (COUNT(employeeID) > 1))
ORDER BY employeeID


Then I discovered that Log Parser would query Active Directory! I knew how to use a simple SELECT statement in VBScript but it didn’t support all the SQL keywords I needed to use. This utility does that beautifully.

I changed my query file to this:

SELECT employeeID,sAMAccountName,sn,givenName
FROM LDAP://domain.org
WHERE employeeID IN
  (SELECT employeeID
  FROM LDAP://domain.org
  GROUP BY employeeID
  HAVING (COUNT(employeeID) > 1))
ORDER BY employeeID


And ran this command and voila! A complex SQL query of Active Directory!

logparser file:myquery.sql -i:ADS -objectClass:User -o:CSV
-headers:ON > duplicate-employeeid.csv


The documentation that comes with Log Parser is very useful and comprehensive. I also found an article (part1, part2) describing how to use Log Parser to view all the different types of Exchange logs and pull information into charts and graphs. I’ll be checking that out for sure.

Download Log Parser here: http://www.microsoft.com/download/en/details.aspx?id=24659
Apparently there’s a book, too: Microsoft Log Parser Toolkit: A complete toolkit for Microsoft’s undocumented log analysis tool

* MS Query located here for Office 2010: c:\Program Files\Microsoft Office\Office14\MSQRY32.EXE.

UPDATE 8/9/2011:

I found today that you can’t use JOIN in the queries for Log Parser. You CAN use the IN keyword to work around this. For a more complicated JOIN workaround, I suppose you could do one query, export it to a file and then do another query based on that.

Sample IN query:

FROM 'directory-size.txt'


4 responses so far

Read CHM files on the iPad

Mar 28 2011

Okay, so I’ve got Dropbox with a whole bunch of tech books in PDF and CHM format.

I’ve got GoodReader for reading PDFs and it connects to Dropbox like a champ. I’ve got CHMate Lite for reading CHM files but I have to use the awful Bonjour (I think it’s Bonjour) wireless interface to copy files from my computer to my iPad in CHMate Lite.

BUT, if I use GoodReader to download the CHM file open the file using CHMate Lite THROUGH GoodReader, I don’t have to mess with the wireless interface! AND it let’s you use CHMate on more than one CHM file. Excellent!

This link will get you and me an extra 250MB when you sign up at Dropbox: http://db.tt/bskdrAA

Here are instructions for connecting GoodReader to Dropbox: http://www.goodreader.net/gr-man-tr-servers.html#read1st

And here, Ali Parvaresh explains how to use GoodReader to open CHM files: http://aliparvaresh.com/archive/2010/07/29/read-chm-files-on-ipad.aspx

UPDATE: 8/9/2011

I’ve found that you can open CHM files directly through the Dropbox app in the same way you can open them on through Goodreader.

  • Download the file through Dropbox.
  • It will complain that it can’t read the file type.
  • Then tap the little box with an arrow in it and you get the same “Open With” dialog you get in Goodreader.

I did find that the Dropbox app doesn’t handle large files (>20MB) as well as Goodreader does.

UPDATE: 6/15/2012

Dropbox now gives you 500MB of free space when you sign up through my link.

One response so far

Older posts »