I've played around with Vidas Matelis' PowerShell scripts for processing SSAS databases the last couple of months. The scripts have all sorts of useful output, but I've been looking for a way to write the error messages to the Event viewer instead of just the command prompt. (Mostly because if you start the script from a short cut, it will just fly through and be gone from the screen when it's finished, and you have no way of knowing what on Earth the output was.)
So, today I've learned 3 new things about PowerShell
1) You can add the parameter -noexit to the command prompt string to make sure the script prompt window stays open after the script has finished running. (You can't rerun the script, though.)
Got the tip from
Hey, Scripting Guy!2) There are two ways to write to the Event Log
Number 1:
Use a Cmdlet to to create an instance of the .NET Framework class System.Diagnostics.Eventlog and then write the entry.
$a = New-Object -type System.Diagnostics.Eventlog -argumentlist System
$a.Source = "Windows PowerShell"
$a.WriteEntry("This is a test.","Information")
More infoNumber 2:
Create a new Soure type and then write to the EventLog.
new-eventlog -LogName Application -Source MySource
write-eventLog -LogName Application -Message "Hello Eventing World" -Source MySource -id 1234More infoI've used the first version in the original ProcessSSASDB.ps1 script, but I'm inspired by the second one to make more changes.
3) I still remember enough of my French lessons 15 years ago to be able to figure out why my code failed from reading a French dev forum on the same thing. :)
http://powershell-scripting.com/index.php?option=com_joomlaboard&Itemid=76&func=view&id=1053&catid=5
J'ai trouvé il y a un espace de trop sur la ligne
$applog.WriteEntry ("Ceci est un message d'erreur.", "error", "1234")
entre WriteEntry et ("CeciI had a space too many between WriteEntry and (" as well.