Powershell – Reboot and Continue Script

There is a great article on TechNet from the Hey, Scripting Guy series that goes over a situation very similar to what you are describing: Renaming a computer and resuming the script after reboot. The magic is to use the new workflows that are part of version 3: workflow Rename-And-Reboot { param ([string]$Name) Rename-Computer -NewName … Read more

Hashtables and key order

There is no built-in solution in PowerShell V1 / V2. You will want to use the .NET System.Collections.Specialized.OrderedDictionary: $order = New-Object System.Collections.Specialized.OrderedDictionary $order.Add(“Switzerland”, “Bern”) $order.Add(“Spain”, “Madrid”) $order.Add(“Italy”, “Rome”) $order.Add(“Germany”, “Berlin”) PS> $order Name Value —- —– Switzerland Bern Spain Madrid Italy Rome Germany Berlin In PowerShell V3 you can cast to [ordered]: PS> [ordered]@{“Switzerland”=”Bern”; “Spain”=”Madrid”; … Read more

How to import custom PowerShell module into the remote session?

There were some great comments to the question, and I’ve spent some time investigating various ways to approach the problem. To begin with, what I’ve initially asked for is not possible. I mean, if you go the module way, then the module should be physically present on a target machine to be able to Import-Module … Read more

How to fetch an attribute value from xml using powershell?

Assuming your XML structure is something similar to: $xml = [xml]’ <Events> <Event Definition=”Validate” DLLPath=”” DLLName=”Helper.dll” DLLClass=”HelpMain” DLLRoutine=”pgFeatureInfoOnValidate_WriteToRegSelectedFeatures” InputParameters=”pTreeViewFeatureTreeServerOS” RunOnce=”no”/> <Event Definition=”Validate1″ DLLPath=”” DLLName=”Helper.dll1″ DLLClass=”HelpMain1″ DLLRoutine=”pgFeatureInfoOnValidate_WriteToRegSelectedFeatures” InputParameters=”pTreeViewFeatureTreeServerOS” RunOnce=”no”/> </Events> ‘ #Or get it from a XML file $xml = [xml](Get-Content $XMLPath) $xml.Events.Event | Select DLLName

How to perform keystroke inside powershell?

If I understand correctly, you want PowerShell to send the ENTER keystroke to some interactive application? $wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate(‘title of the application window’) Sleep 1 $wshell.SendKeys(‘~’) If that interactive application is a PowerShell script, just use whatever is in the title bar of the PowerShell window as the argument to AppActivate (by … Read more