powershell

Slow Powershell function. How to Improve?

I have written the below Powershell function to call an F5 unit. It loops round for each server and gets each individual stat and then executes a SQL SMO call. The code is running really slowly and i think i have discounted the SQL call as the cause. How can the powershell be improved? function Print-VServerStats() { param($virt...

TrustAllCertificatesCallback is ignored

Given a url or server name, how can i use powershell or a .net library to download the (expired) certificate the web server is using and then save it to file or import it into my certificate store? Thanks! I have made progress, i got this far on this problem: static class Program { static void Main() { ...

Command-line interface or PowerShell?

If you were to make a tool that: sys-admins would use (e.g. system monitoring or backup/recovery tools) has to be script-able on Windows Would you make the tool: A command-line interface tool? PowerShell cmdlet? GUI tool with public API? I heard PowerShell is big among sys-admins, but I don't know how big compared to CLI tools. ...

Can I use System.Core.dll/System.Collections.Generic.HashSet in powershell?

I'd like to use a HashSet in a powershell script. I think I've figured out how to instantiate generic collection objects by doing: [type] $strType = "string" $listClass = [System.Collections.Generic.List``1] $listObject = $base.MakeGenericType(@($t)) $myList = New-Object $setObject This works fine for lists and dictionaries, but when ...

How to launch PowerShell script from the OS command line?

I have a PowerShell script for building my project files, and I'd like to have capability to run it from my file manager's command line (and, possibly, make a shortcut to this script so I can start build from my desktop) Any way to do this? ...

How does threading in powershell work?

I want to parallelize some file-parsing actions with network activity in powershell. Quick google for it, start-thread looked like a solution, but: The term 'start-thread' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the ...

Powershell exit does not work

I am writing a script which checks for a registry value and and exits if is 0. (It will proceed if the value is 1.) if ((Get-ItemProperty -path HKLM:\SOFTWARE\ICT\LoginScript).proceed -eq 0) { $form.close() exit } When I run the script with the reg value at 0, it fails to exit and throws an ex...

Problems debugging a PowerShell cmdlet

I'm using Visual Studio 2010 on Windows 7 64-bit Professional. I'm having trouble debugging a custom PowerShell cmdlet. Configuration Language: C#, targeting .NET Framework 3.5 SP1. Platform target: Any CPU Start Action: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe Command line arguments: -noexit -command Add-PSSnapIn MyC...

An example of using the 'from' and 'data' keywords?

Thanks to this article, I was able to come up with a script which sorts and displays the keywords PowerShell provides: $bindingFlags = [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static -bor [System.Reflection.BindingFlags]::GetField $keywordTokenReader = [System.Type]::GetType("Sys...

Powershell and enums defined in C++/CLI assembly

I have an assembly written in C++/CLI that contains a heap of enum defined like the following, one after the other in a single header file. namespace Fix { public enum class Side { SideBuy = '1', SideSell = '2' }; } I can reference these types in other C# projects, and in IronPython, I can reflect the assembly and see them a...

Powershell webbrowser refresh makes my content disappear

I am writing a small powershell script using windows forms which generates an HTML signature. The user can edit size, color etc and the script generates the html as a from their choices, and updates (theoretically) my WebBrowser preview when they press a preview button. My WebBrowser Control: $Preview = new-object System.Windows.Forms...

Which .NET version is my Powershell script using?

I'd like to use .NET in some PowerShell scripts I'm about to write -- how do I know/declare which version of .NET I'm dealing with when these scripts run? EDIT: And is it possible to choose against which version of .NET my script will run? ...

Best approach to build reusable C# data integration assemblies

How have you addressed the issues when building a reuseable suite of C# data integration assemblies? We're a Microsoft shop using Sql Server and C#. We're consolidating a lot of our DB integration code into C# assemblies. In doing so we're hitting a number of common problems. 1) We like the source/destination flexibility of SSIS and th...

Fill in a column in a CSV file using POWERSHELL V2

i have a CSV file : COL1;COL2;COL3;COL4 1;1;;4 6;9;;0 9;8;;4 How do i fill in COL3 with a default value X? so the result would be : COL1;COL2;COL3;COL4 1;1;x;4 6;9;x;0 9;8;x;4 How can i achieve this using Powershell V2 or even ultra edit or Notepad++ Thanks ...

Running powershell scripts from within a .NET windows app

I'm needing to run scripts from within a vb.net windows app. I've got the scripts running in the background fine; Using MyRunSpace As Runspace = RunspaceFactory.CreateRunspace() MyRunSpace.Open() Using MyPipeline As Pipeline = MyRunSpace.CreatePipeline() MyPipeline.Commands.AddScript("import-module -name " & module...

Having problems with Powershell ConsoleShell.Start

Running the following code resulting in an HostException; Public Sub RunPowershellInConsole(ByVal scriptText As String) Dim config = RunspaceConfiguration.Create Dim args() As String = New String() {scriptText} ConsoleShell.Start(config, "Windows PowerShell", "", args) End Sub . System.Management.Automation.Host.Host...

Windows Forms look different in Powershell and Powershell ISE. Why?!

I have written a script which is basically a small wysiwyg signature generator for Outlook. We want our signatures to be in corporate colours, and semi-standardised - hence the requirement for this. I did the development work in Powershell ISE and all looked good. However, when I run the script just using powershell (as the users will) ...

Using JScript in powershell

Reading through the documentation for powershells add-type it seems you can add JScript code to you powershell session. Firstly is there a decent example of how this is done and secondly can you use this to validate normal javascript code (as I understand JScript is the MS implementation) ...

Custom PowerShell Snapin: custom format doesn't work

I used this article to write my first own Powershell Cmdlet and Snapin. And it works fine. But I return a set of objects from my own data class, which has four properties and I want Powershell to display just one of these properties by default. So I used this part of the article to create this format file: <?xml version="1.0" encoding=...

Advantages of Powershell for web-ui testing?

Hi, I am working on a commercial project which is a web-based app which will be bundled with an app/web server (JBoss), which is deployed, with the web app files, at runtime. I've seen links about how Powershell can do UI testing. Is there any advantage in Powershell for web-testing as opposed to Selenium or VS2010's coded UI tests? (S...