I'm using powershell a lot for performing upgrade actions on an existing Sharepoint installation. I try to keep the manual tasks to a minimum, since the (exact) same actions must be executed on different environments (DTAP).
Powershell scripts won't execute like a command file (like double-clicking in the explorer). Instead you need to open a commandline, navigate to the correct folder, start the powershell environment and then you can execute the powershell script. This is not so much an issue when a whole set of scripts need to be executed, but when I just want to run a single script this feels like a lot of work just to start a single script. So to make executing a powershell script a little easier, I've created a simple command file that will execute a single script. It works simply by dropping the desired powershell script on it in the explorer.
Create a command file with a name like 'ExecutePowershell.cmd' and put in the following code:
echo Execute powershell:
powershell.exe "& "%1%""
The trick here is of course in the way powershell is started. You can use this syntax to run scripts from a file, like so:
powershell "& .\scriptfile.ps1"
Don't forget the .\ if you're running a script from the current directory (or powershell won't find the script). And when the path to the script contains spaces, place it between double double quotes (because the quotes are used within an, already quoted, string), like so:
powershell "& ""Installation Scripts\scriptfile.ps1"""
Or run a single (or several) statements, like so:
powershell "& get-process"
With a previous post, I had some trouble with the code-formatting in BlogEngine.NET. I didn't have time to investigate, so I quickly fixed it with some inline styling. But planning to post some more code in the future, I decided to look into it today. Quickly I found my problem: I had forgotten to put the language into the code-element. So in that particular case I added ':js' and it all worked fine.
Now I had code-formatting working, but I wasn't very pleased with the results. Having looked at the code, I found the options for adding line-numbers and alternating line-styles. A first issue was that the line-numbers didn't align correctly. I thought it would be a minor styling issue. But then, adding more lines of code, my whole page layout got messed up. After a quick look at the code I found the problem: an alternating row is started with a p-tag, but is ended with a div-tag. This is fixed with a small modification as demonstrated below:
Another thing I noticed, was that the tabs or spaces in front of a line didn't show. This happens because browsers render multiple spaces as a single space. The code formatter changes a tab into a number of spaces, which I decided to change as follows:
- In the same SourceFormat.cs, locate the following line (almost at the top of the method):
- Replace it with the following code:
StringBuilder tabSpaces = new StringBuilder();
for (int tabIndex = 0; tabIndex < _tabSpaces; tabIndex++)
- Again, save the changes and upload the file
This only correctly replaces tabs in the code, not spaces. I guess a better solution would be to leave the original Replace, and then replace all leading spaces with . But that's for another time ;-).