Windows Powershell script opens notepad

I was going to automate AD user creation with powershell on server 2008 R2 but have hit a problem.

When I try to run the addUser.p1 script from the powershell command line or from a CMD shell using powershell.exe addUser.p1 with or without the full or relative path (from within the directory where the script resides) notepad.exe opens.

I have only 2 lines in the script as I wanted to see if it was the script causing problems. It takes the username as an arg and creates a profile directory based on the username.

The script is as follows:

$serverName = "SERVER03"

If I run the test command '[IO.Directory]::CreateDirectory("\\SERVER03\profiles\testUser"' directly in powershell then it does indeed create a directory.

I have already run 'Set-ExecutionPolicy RemoteSigned' and am running the script on the server itself.
Who is Participating?
excelsupportAuthor Commented:

I saved the script file as sp1 rather than ps1. Knew it would be something simple...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.