Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Dec 4, 2009

File .ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

I got this error on Windows PowerShell when I tried to run a script stored in file abc.ps1. The error read:


File C:\sql_job.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.



Now the solution was that you need to modify the script execution policy to enable powershell to run external scripts. Now there are multiple options here as what could be set but for a developer environment, if you set the execution policy to unrestricted it should do.
To do that, type following at  your powershell command prompt:



PS C:\Documents and Settings\Administrator> set-executionpolicy Unrestricted



PS C:\Documents and Settings\Administrator>


Once you type that and press return key, you will be able to execute your .ps1 script file without any problems. Regarding execution policy options, it is likely candidate for a separate blog post!

You can have a more detailed look regarding execution policy options here http://www.informit.com/articles/article.aspx?p=729101&seqNum=7

Nov 24, 2009

How To Delete Event Logs

I had this requirement of deleting event log once. Now I wonder why there is no delete log option when we are viewing the event log using windows event log viewer.
One alternative was to create a small utility in .NET and run it which deletes the particular event log. It worked but was time consuming. Then I came across this cool stuff which you do with powershell! Just one line and you can delete event log!

Just open powershell and type in the following. Caution! it will not ask for confirmation and will immediately delete event log.

[system.diagnostics.eventlog]::Delete("YourEventLogNameHere")
I tested it with windows powershell v1.0