powershell-v2.0

Add reference to dll in powershell 2.0

Hi folks, I create dll in c# and i want to use it in powershell, but without reflection. i know i can load the dll using: [Reflection.Assembly]::LoadFile("MyDll.dll") But i don't want to use reflection. is there any simple way to do it? something like add reference to this dll... Thanks in advance ...

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=...

command line arguments in Powershell

So the problem is, that when I run my basic script that simply mirrors whats is passed in on the command line, the arguments aren't separated in the way I would expect them to be. the basic code is: write-host "`$args`[0`] = $args[0]" write-host "`$args`[1`] = $args[1]" write-host "`$args`[2`] = $args[2]" and if i call the script a...

How to iterate the irregularly-named children of an Xml.XmlElement in Powershell?

I have an XML file of the following format: <xml> <data> <foo float="99.0"/> <bar float="12.0"/> <tribble bool="true"/> ... <flibble int="1"/> </data> </xml> If I fetch that data in Powershell, I can see all the child elements of data with a Get-Memeber: > $xmlData = [xml](Get-Content m...

CruiseControl.Net not playing nice with PowerShell

Here is my PowerScript Task <powershell> <script>RunScout3G.ps1</script> <executable>C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe</executable> <scriptsDirectory>C:\Program Files\CruiseControl.NET\Our_PowerShell</scriptsDirectory> <buildArgs></buildArgs> <successExitCodes>0</successExitCodes> <buildTi...

How do you Uninstall and Install an application REMOTELY using PowerShell 2.0?

I understand I can use to following to install and unintall locally, but how can I push this onto another server that is on the same network and same OS version? Thanks in advance. (Get-WmiObject -Class Win32_Product -Filter "Name='MyMSI'" -ComputerName . ).Uninstall() (Get-WMIObject -ComputerName Hello -List | Where-Object -FilterScr...

Powershell -contains/-notcontains - having trouble with an array result from SQLServer

I am using Invoke-SQLCmd to get a list of items that I want to process. In that list may be an item that indicates that the entire list needs to be bypassed. I have tried to figure out how to use the -contains and -notcontains operator but I am not having any luck. This would be the pseudo code: $dont_process = "dont process" $list = In...

Using Powershell to automating a bat file that ends with PAUSE

I have a batch file that I can't change, but I want to automate with Powershell 2.0. It ends with a PAUSE command, which displays: Press any key to continue... Is there an way to call this batch file from a powershell script, but have it exit without needing a user to press something? ...

Powershell: How to capture output from the host

I am using powershell to automate some tasks related to checking out/merging in TFS. When I call tf get * /recurse I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it c...

Process list of commands on remote machine with Invoke-Command

Hi there, I'm trying to write a powershell script that will take a list of commands and then run them on a remote machine, I have the following code: foreach($command in $commands) { Invoke-Command -computer "BNEBAK" -scriptblock{"$command"} } Which does not throw any error but also does not actually run the command (e.g stop-servi...

hosting powershell like cli in asp.net mvc to perform maintaince

I need CLI for our asp.net mvc application to perform maintenance tasks and some status tasks. I think powershell is designed to provide CLI. But i do not know anything about it other than name. How can i host powershell in asp.net mvc running in iis to provide CLI for custom tasks? ...

Redirect write-host to a textbox in a form?

I suppose my question is somewhat similar to this: http://stackoverflow.com/questions/2607865/redirecting-the-standard-output-input-error-into-from-a-textbox but it is powershell-centric. I'm working on an GUI created using PrimalForms that will act as a frontend to my website deployment scripts. Up until now, I've been using start-tra...

Powershell: How can I pass a variable as a parameter value?

I have code that prompts a user for input for $dom. $dom = "'DC=my,DC=com'" Get-QADUser -SearchRoot $dom -SearchScope 'SubTree' -objectattributes @{"EmployeeID"=$eid} | Select-Object SamAccountName, employeeID, DisplayName, Description, Email, LastLogon, legacyExchangeDN I get the following error when I run this. Get-QADUser : A ref...

Cannot install Powershell Snap-in

When executing iis7psprov_x64.msi I immedialy receive a message saying: The PowerShell snap-in is part of Windows Operating System. Please install it via 'Programs and Freatures' or 'Server Manager' Extracting the msi and attempting to run it that way also yields the same message. I am installing on Win7(64bit) with IIS 7.0. ...

How do I use Add-Type to load Microsoft.Web.Deployment

I am writing some PowerShell scripts that use msdeploy api. I can load the assembly using The location is in the GAC PS > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment") | fl Location Location : C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Deployment\7.1.0.0__31bf3856ad364e35\Microsoft.Web.Deployment.dll ...

create, Edit , Delete Virtual directory ,Website,Application in powershell

Hi i created and deleted the virtual directory its working fine but need to modify name , port Path plz help me ...

How to run function in deiffetent runspace, PowerShell

Hi, I have powershell script that add registration to event, but when the event is jump i'm getting the following error every time the event is jump: "no Runspace available to run scripts in this thread" I'm using PS v2, what can i do? Can you provide some code? Thanks ...

Digital Signature un PowerShell v2

Hi, How can i create digital signature using PowerShell, is there any build-in commands for that? It should be same to the open SSL command: openssl dgst -sha256 -sign TIA ...

PowerShell Socket object different if created through function, vs. through the CLI

I have a function: function QuerySMTPServer ([string]$strSMTPServerName) { # open up a socket to the SMTP server $socket = New-Object System.Net.Sockets.TCPClient $socket.connect($strSMTPServerName, 25) $socket # output for testing # read response data (should be a line starting with 220; cf. RFC821) $stream = $...

Invoke function in new thread powershell

How can i create new thread and running in async? i have an event which should update text box in run time so i need to run it in different thread. (powershell 2). How can i do it in PowerShell? ...