Archive for March, 2010

Not recognized as a cmdlet…

I have been working on a simple little script to copy a file and then launch a program.  I am sure that there are a lot of ways to do it, but I decided to use PowerShell, and this is what I came up with:

$CheckForFile = "H:\custom.ini"
$FileToCopy = "c:\IT\custom.ini"
$CopyFileTo = "H:\"

$PathTest = Test-Path $CheckForFile
If ($PathTest -eq "false")
    {
    Copy-Item $FileToCopy $CopyFileTo
    }

#uses the Invoke-Item command to launch the application
Invoke-Item "C:\Program Files\executable to launch.exe"

This is for use in a Citrix/Terminal Server environment, so I want to be able to call this script like this: PowerShell copythenlaunch.ps1

When I tested that, I got this:

C:\IT>powershell copythenlaunch.ps1
The term ‘copythenlaunch.ps1′ is not recognized as a cmdlet, function, operable
program, or script file. Verify the term and try again.
At line:1 char:18
+ copythenlaunch.ps1 <<<<

I kept thinking there was some problem with the install of PowerShell (I am running this particular script on a Windows 2003 Server) or that I had some illegal character in the name (it had a number in it originally) or some other simple problem.  Finally I did a search and came across this little bit of conversation:

re: Power and Pith

I just started with PowerShell.

Wanted to run some test scripts from you download.

When I tpye in Beep.ps1 I get "The term ‘Beep.1′ is not recognized….."

What Am I doing wrong?

Friday, December 29, 2006 3:17 PM by MikeL

# re: Power and Pith

> When I tpye in Beep.ps1 I get "The term ‘Beep.1′ is not recognized….."

> What Am I doing wrong?

You are relying upon a traditional bad shell behaviour that has been a security nightmere for decades.

In PowerShell, you have to be explicit if you want to run a command in the current directory.  Type ".\beep.ps1"

Jeffrey Snover [MSFT]

Windows PowerShell/MMC Architect

Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Friday, December 29, 2006 5:19 PM by PowerShellTeam

# re: Power and Pith

Thank You for supplying the ".\*" information.  I have been racking my brain for almost two days wondering what I was doing wrong.  And to think it was as simple as using the PROPER .\yourscripthere.ps1 format.

Thank you very very much

Ditto on the thanks…

Windows PowerShell Blog : Power and Pith

Ha Ha – “408 error”

For some reason this struck me as funny…  Got it when I went to view the WordPress stats for my blog…

image

PowerShell Confirm Preference

I seem to run into an issue when I run some PowerShell scripts where I get prompted at each line of the script for confirmation.  That can get really annoying, so I have to look up how to prevent that behavior.  Thankfully, there is already some good information out there on how to do that:

When confirmation is turned on by $ConfirmPreference, you can turn it off for any individual cmdlet invocation using "-Confirm:$false".  You can also use "-Confirm:$false" to turn off default confirmation for high impact cmdlets such as Removing a Mailbox.  Another way to turn off confirmation is by setting $ConfirmPreference to "None"; you can limit the effect by setting $script:ConfirmPreference etc, see "get-help about_scope" for more details.

For more details and options besides just turning it off, go see the original post:

Windows PowerShell Blog : ConfirmPreference