powershell-v2.0

Send data to putty in powershell

I have powershell script that open putty.exe in process and i want to send data to this process, how can i do that??? PLEASE HELP! The process: $solExe = [diagnostics.process]::start("putty.exe", "-raw -P 2000 127.0.0.1") ...

Windows PowerShell 2.0 for the absolute beginner - errors on the last project in the book

Hello, Working through Jerry Lee Ford Jr.'s Powershell 2.0 for the Absolute Beginner book. There's a lot of typographical errors in the code of the book that I've been able to work through and correct (great practice), but there's one I simply can't seem to figure out. Downloaded his stock code from the companion website, and his code i...

Add-Type PowerShell 2.0 can't find method.

I've made a c# class that I'm trying to run in PowerShell with add-Type. I have a few of my own assemblies referenced and some from .net4. I'm using my own PowerShell host because the assemblies I'm referencing are made on the .net4 framework and the PowerShell Console doesn't support that yet. Here is a sample of the script that i'm tr...

Why is my call to Runspace.Open() not returning?

I am trying to integrate some new code I wrote for programmatically interacting with Exchange 2010 via Remote Powershell into an existing WinForms application. My code works in an isolated test application, but when I run the code in the context of my app the call to Runspace.Open() blocks for a very long time -- well past the OpenTimeou...

Powershell remoting ApplicationArguments not working

I'm trying to pass some arguments into a new Powershell remoting session using the PSSessionOption's ApplicationArguments property. Unfortunately, the arguments don't seem to show up. Here's the code: $client = "Bubba" $options = New-PSSessionOption -ApplicationArguments @{ Client = $client } Enter-PSSession -ComputerName "Server" -Se...

preventing a cmdlet from freezing powershell

I created a cmdlet that automates keystrokes to window. When I attached that window to the debugger and perform long debugging operations, powershell freezes and even ctrl+c is not recognized. Can you help me with this? thanks :) ...

Powershell 2.0 generates nulls between characters

With powershell 2.0: write-output "abcd" >> mytext.txt writes: a nul b nul c nul d nul od -c shows the nul as a true binary zero, \0 , or: a \0 b \0 c \0 d \0 (and \r \0 \n \0) I am trying to generate some SQL, so I don't think this will do. Any ideas of what's going on and how to use write-output to just get the specifie...

Show failure for SQL 2005 Job that executes Powershell script through CMD prompt, IF PS script fails

I have a SQL 2005 instance that runs a job that uses a Powershell script to rename the current SQL TX Log backup file by appending "-PrevDay" to it, (subsequently deleting the backup already named "XXX-PrevDay.bak" if it exists), and then run a full backup of the DB and a TX Log backup, if the DB is not in Simple mode. SQL Job kicks off...

Cannot Start Service when launching installer with script from remote Powershell runspace..

I'm launching an installer on a remote machine using powershell with a remote runspace: some code hidden but you get the jist... I create my PSCredential in C#: PSCredential pwd = new PSCredential(cred.UserName,PowerShellEngine.GenerateSecurePassword(cred.Password)); ConnectionInfo = new WSManConnectionInfo( false, cred.HostName, 5985...

How to check if a cmdlet exists in powershell at runtime via script

I have a Powershell script that needs to run under multiple hosts (PowerGUI, Powershell ISE, etc...) but am having an issue where sometimes a cmdlet doesn't exist under one of the hosts. Is there a way to check to see if a cmdlet exists so that I can wrap the code in an if block and do something else when it does not exist? I know I co...

Powershell select-string

I would like to search for more than one strings of the files in directory however the select-string -pattern didn't help. Could anyone show me how to do it. Example: Search all files in C:\Logs that contains the words VendorEnquiry and Failed and Logtime about 11:30 am. Structure of files may different e.g different tag names etc.. eg...

Changing the physical path of an IIS website on a remote machine via Powershell

Hi All, I'm currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remote web server, and then switch the physical path of the existing site to the new directory. So far I have everything working except for switching the phys...

Powershell Backgroundworker

Can anyone give me an example of how to use BackgroundWorker in Powershell? I want to write something so when a new tab is selected in my Powershell GUI app, it will switch to the tab with a "please wait" message displayed, then run some checks in a BackgroundWorker thread, and then update. Is this possible in Powershell? All the Googl...

How to attach a file to an email with PowerShell

I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong? $ol = New-Object -comObject Outlook.Application $message = $ol.CreateItem(0) $message.Recipients.Add("Deployment") $message.Subject = "Website ...

how to select elements of a byte array, with variable length strings.

Hello, Trying to decode a UDP message, it is an array of 128 bytes, the first variable length string begins at the 7th byte. What I would like to do is split the array into individual elements and decode each element based on the type(byte,string). The data format/types are defined here: http://developer.valvesoftware.com/wiki/Server_que...

Return SQL Query as Array in Powershell

I have a SQL 2008 Ent server with the databases "DBOne", "DBTwo", "DBThree" on the server DEVSQLSRV. Here is my Powershell script: $DBNameList = (Invoke-SQLCmd -query "select Name from sysdatabases" -Server DEVSQLSRV) This produces my desired list of database names as: Name ----- DBOne DBTwo DBThree I has been my assumption that a...

Running PSAKE script from the command line

I'm creating a batch file to execute my psake builds while integrating with teamcity and the TFS Powershell commandlets from TFPT and have come up with the following: @ECHO OFF SET COMMAND_TO_EXECUTE= SET COMMAND_TO_EXECUTE=%COMMAND_TO_EXECUTE% "& { SET COMMAND_TO_EXECUTE=%COMMAND_TO_EXECUTE% Import-Module '..\tools\psake\psake.psm1'; ...

PowerShell "execution of scripts is disabled on this system."

Hi Folks, I am trying to run the a .cmd file that calls a powershell script from the command prompt and I am getting the below error: "Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system." I have ran the set-executionpolicy unrestricted and when I do a get-executionpolicy from Powershell...