Create PSCredential without a password
Solution: $mycreds = New-Object System.Management.Automation.PSCredential (“username”, (new-object System.Security.SecureString))
Solution: $mycreds = New-Object System.Management.Automation.PSCredential (“username”, (new-object System.Security.SecureString))
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
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
If you’re running Windows 8/Windows Server 2012 or newer, you can use the Test-NetConnection command in PowerShell. Ex: Test-NetConnection -Port 53 -ComputerName LON-DC1
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
In your particular case what you want is Tree /f. You have a comment asking how to strip out the part at the front talking about the volume, serial number, and drive letter. That is possible filtering the output before you send it to file. $Path = “C:\temp” Tree $Path /F | Select-Object -Skip 2 … Read more
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
I think this need to be run from the Management Shell rather than the console, it sounds like the module isn’t being imported into the Powershell console. You can add the module by running: Add-PSSnapin Microsoft.Sharepoint.Powershell in the Powershell console.
The documentation for try-catch-finally says: A Finally block runs even if you use CTRL+C to stop the script. A Finally block also runs if an Exit keyword stops the script from within a Catch block. See the following example. Run it and cancel it by pressing ctrl-c. try { while($true) { “Working..” Start-Sleep -Seconds 1 … Read more
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