You’ve Got To Be Kidding Me – 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 192.168.1.1″ > $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 192.168.1.1″ | 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

Installing DokuWiki on IIS 7.5 in an Active Directory environment

Sep 21 2012

The Issue:

I’m installing DokuWiki on IIS 7.5 / Windows 2008 R2. While running the install.php file, I ran into this set of errors:

{DOCUMENT_ROOT}\dokuwiki/conf/ is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/pages is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/attic is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/media is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/meta is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/cache is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/locks is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/index is not writable by DokuWiki. You need to fix the permission settings of this directory!
{DOCUMENT_ROOT}\dokuwiki/data/tmp is not writable by DokuWiki. You need to fix the permission settings of this directory!

I found one forum thread specific to this and the answer was all the way at the bottom but wasn’t too clear so I’m writing up the fix here. (All the other Google links were about fixing the issue on non-IIS web servers.)

The Fix:

I granted “Authenticated Users” Write access to the dokuwiki\data and dokuwiki\conf directories, restarted the website in IIS Manager and was able to continue with the install.

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.

ad-search

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:

SELECT DIR As UserID, SIZE_MB As Dir_Size_MB
FROM 'directory-size.txt'
WHERE UserID IN (SELECT USERID FROM 'users.txt')
ORDER BY Dir_Size_MB DESC

 

2 responses so far

Older posts »