Archive for the ‘Technology’ Category

Index.php Wouldn’t Load Correctly

Thursday, January 12th, 2017

I managed to screw up my website at some point. Index.php would not load correctly. You would instead be prompted to download a file. Other WordPress websites in my hosting package worked correctly and other PHP pages in this website worked — just not index.php.

I casually troubleshooted it at times and kept being pointed to htaccess or the PHP configuration being the problem but nothing I found worked. Today I decided to get to the bottom of it. Obviously it was something relatively simple since the other sites and pages worked, I just had to find it. I compared the htaccess file between this site and another similar WordPress site I have. Both were exactly the same. There were some permission differences between the directory structures — mostly the “group” part of the permissions didn’t have read and/or execute rights on this site. Changing the permissions didn’t change the behavior.

Finally I saw a comment about having an index.html in the root directory of the site. I didn’t have that file but I did have index.html.old and index.php.old. I don’t remember what either of those were used for but I moved them both out of the directory. Boom! The site loads correctly now. I went a little further to figure out if one or both of the files was the actual problem and it turns out index.html.old was the issue. So even though it wasn’t named index.html (or index.htm), apparently Apache found it and tried to load it instead of index.php.

Powershell and Unicode

Tuesday, October 23rd, 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

Watch Youtube Videos At A Faster Speed

Friday, June 22nd, 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:

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

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

Wednesday, May 30th, 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.

Microsoft Log Parser: Coolest Thing Since Sliced Bread

Tuesday, August 9th, 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
WHERE employeeID IN
  (SELECT employeeID
  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:
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'