powershell

How to tell powershell to wait for each command to end before starting the next?

I have a powershell 1.0 script to just open a bunch of applications. The first is a virtual machine and the others are development applications. I want the virtual machine to finish booting before the rest of the applications are opened. In bash I could just say "cmd1 && cmd2". This is what i've got... C:\Applications\VirtualBox\vbox...

Creat AppPool and virtual directory on a remote server using Powershell

How do I creat AppPool and virtual directory on a remote server using Powershell on iis6 ...

WCF + WebClient + Powershell

Hi, I tried it works fine for the asmx (simple web services) but for WCf do we need to do some thing different. Can the Same work for the WCF services as i get the error for the WCF service also. i just created the Simple WCF service in .net and tried to access. but was not successful. Error: $Url = "http://localhost:4637/WCFService2/...

Run a program from PowerShell with timeout

I'll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed. ...

Run remote process by powershell

I have the following line of code to create object to access to a remote server before I associate it with user name, password and process: $process = [WMIClass]"\\remoteServer\ROOT\cimv2:Win32_Process" I tried this on two PCs, one is OK without any errors, but another one I am going to run has an exception: Cannot convert value "\\...

How to recursively delete an entire directory with PowerShell V2

What is the simplest way to forcefully delete a directory and all its subdirectories in PowerShell? I am using PowerShell V2 in Windows 7. I have learned from several sources that the most obvious command, Remove-Item $targetDir -Recurse -Force, does not work correctly. This includes a statement in the PowerShell V2 online help (found u...

Powershell setting COM+ Enforce access checks for this application

Hi, I'm having problems figuring out what is the Powershell string for choosing the "Enforce access checks for this application" under the Security tab of the properties for that application. Here is what I have so far for Powershell in choosing other things: $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog $apps = $comAdmin...

Retrieving data using select SQL statement in Powershell

My goal is to assign the value of the results returned to a variable: $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=HOME\SQLEXPRESS;Database=master;Integrated Security=True" $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = "select name from sysdata...

Debug PowerShell using PowerGUI

I use PowerGUI to edit my script. In Visual Studio, I can add command line argument from project properties. However, I cannot find a way to set parameters to the UI to debug my codes with specified $args. For example, I set one debug point in PowerGUI, first line of my start code. Then I try to start my script from UI's panel "PowerShe...

PowerShell Get-Item question

I am new to PS. Here is an example of my function codes: function foo() { # get a list of files matched pattern and timestamp $fs = Get-Item -Path "C:\Temp\*.txt" | Where-Object {$_.lastwritetime -gt "11/01/2009"} if ( $fs -ne $null ) # $fs may be empty, check it first { foreach ($o in $fs) { # new ...

Mutually exclusive powershell parameters

SCENARIO I'm writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|bar] p1, p2 That reads as the user must give a value for "-foo" or "-bar" but can't give both together. EXAMPLE OF VALID INPUT cmdle...

PowerShell STDOUT Formatting Issue

Is there a way to capture STDOUT information from an executable within powershell, without affecting the default behaviour of the STDOUT process? Whenever I attempt to capture output from an executable within PowerShell, it appears that the STDOUT is then formatted before being returned to the host/screen. Further, it also appears that...

How to replace a pattern in a file with an argument in Powershell

I have a powershell script that is replacing patterns in a file with the argument passed to the script. I grabbed the algorithm from another site and it works great, except for the fact that when I use anything but a literal string, the pattern isn't replaced. Here's the original script: (Get-Content c:\File.txt) | Foreach-Obje...

Replacement for Vern Buerg's list.com in 64 bit Windows 7

I would like to find a replacement for list.com, specifically the ability to accept piped input. For example: p4 sync -n | list which accepts the output of the perforce command and displays the results in the viewer/editor for manipulation or saving. I know that I would send the output to a file and then open the file in the viewer/ed...

Powershell: Is it possible to set-alias on a piped command?

I would like to set the following alias up in my powershell profile: set-alias mem-users get-process | ? {($_.PM -gt 10000000) -or ($_.VM -gt 10000000)} | sort -property PM But when I try this out and call mem-users I just get the results of get-process. How would I set this up? Do I have to write a custom function? The examples fo...

How do I encode a 4-byte string as a single 32-bit integer?

First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not important, if that helps. The funny ...

Fast and simple binary concatenate files in Powershell

What's the best way of concatenating binary files using Powershell? I'd prefer a one-liner that simple to remember and fast to execute. The best I've come up with is: gc -Encoding Byte -Path ".\File1.bin",".\File2.bin" | sc -Encoding Byte new.bin This seems to work ok, but is terribly slow with large files. ...

Get index of current item in Powershell loop?

Given a list of items in powershell, how do I find the index of the current item from within a loop? For example: $letters = { 'A', 'B', 'C' } $letters | % { # Can I easily get the index of $_ here? } The goal of all of this is that I want to output a collection using Format-Table and add an initial column with the index of the cu...

Run PowerShell scripts on remote PC

I have installed PS 1.0 on a remote PC(RPC001). I used Windows Sysinternals tool PSExec.exe to execute the following process on the remote: PSExec \\RPC001 -u myID -p myPWD PowerShell C:\script\StartPS.ps1 par1 par2 I can see the PowerShell.exe process running on the remote PC afterwards, but it is actually doing nothing, just hangin...

Powershell: how to tell Copy-Item to unconditionally copy files

This Powershell script: Copy-Item $src_dir $dst_dir$agent_folder -recurse works if the resources are not there. But if the resources are there, it will say: + Copy-Item <<<< $src_dir $dst_dir$agent_folder -recurse + CategoryInfo : ResourceExists: (C:\Users\Pac\Desktop\Agents\Agent0\lib:S tring) [Copy-Item], IOEx...