Posts

Showing posts from March, 2016

Converting markdown files to PDFs

Image
While it is awesome reading the PowerShell DSC documentations in nicely markdown, formatted webpage, I am still emotionally attached to the printed paper in the digital age. (Rubbing my sore eyes) So task is to find a way converting those markdown formatted docs in to PDFs and then print them. I found a couple resources available for this task: GitPrint.com PanDoc Here is my recommendation: Use GitPrint.com whenever you can for smaller batches of conversion. It's easy to use with a javascript based bookmark for page redirection. (The Chrome plug-in is no longer available) As for PanDoc, I installed it along with the MikTex, LaTex's implementation on Windows, for PDF converstion. First, the installers together are over 200 MB download and install. Second, about 70% of the files were converted fine (no colour syntax like GitPrint though) but the rest came out with formatting issues. It could still be valuable when converting a large batches though. You *may* save some ti

PowerShell: Loop through a collection, N objects at a time

Recently I want to loop through a collection of objects and do something with each object. Well, that's a common task in PowerShell. The problem using a loop is it does one object at a time and flow control is limit in this fashion. So it can launch the work to all objects very fast using jobs or slow when iterating though each single one and wait. I want something in the middle. So I spent some time and wrote something that can be used to provide the flow control while enabling multiple running executions. It can be useful in the scenario of upgrading the vmware tools in the vm guests where Invoke-Command doesn't suit the purpose fully. The goal is to go through a collection of objects and:     - Perform some work to the collection in smaller batches of  N     - The batch work should be sent to background for "parallel" execution     - Have a way to check the status of each object in the batch work     - If completed work(s) is found, pull next object(s) fr

PowerShell codes in PowerCLI's Invoke-VMScript

Image
PowerCLI has a nice Invoke-VMScript cmdlet that runs powershell (by default) in a guest via vmware tools. It is very handy in certain cases. For example, servers in isolated or inaccessible  network. Also using it during the server provisioning process sometimes can be helpful. You can use it to invoke a single cmdlet. Just pass what you want to run in the guest to the -ScriptText syntax (enclosed in " or '). Invoke-VMScript will redirect the output from guest to your PowerShell session. Invoke-VMScript -VM 'guestVM' -ScriptText "Get-Process" -GuestCredential $guestcred What if you have a couple cmdlets to run? Separating them with semi-colon works fine. Invoke-VMScript -VM 'guestVM' -ScriptText "Get-Process ; Get-Service" -GuestCredential $guestcred Things start to get interesting/ tricky when you have special charters ($, ", '). For example, say you want to output some text on the screen or trying to do some stu