powershell

Why tee'd variables aren't visible in later scripblocks?

Someone knows for which strange reason Powershell doesn't show de 'tee'd' variable in the following snippet? # a.txt contains any text cat a.txt | tee -variable foovar | % { 'value of foovar: ' + $foovar } In practice, I'd like to do, in only one line, a search for some text and then, based on the results, process the text, for exampl...

Why tee’d variables aren’t visible in later scripblocks?

Someone knows for which strange reason Powershell doesn't show de 'tee'd' variable in the following snippet? # a.txt contains any text cat a.txt | tee -variable foovar | % { 'value of foovar: ' + $foovar } In practice, I'd like to do, in only one line, a search for some text and then, based on the results, process the text, for ...

How to remove item from an array in PowerShell?

Hi there, I'm using Powershell 1.0 to remove an item from an Array. Here's my script: param ( [string]$backupDir = $(throw "Please supply the directory to housekeep"), [int]$maxAge = 30, [switch]$NoRecurse, [switch]$KeepDirectories ) $days = $maxAge * -1 # do not delete directories with these values in the path $...

PHP Powershell command

Trying to run the following command in php to run powershell command... the following works: $output = shell_exec(escapeshellcmd('powershell get-service | group-object')); I can not run it like this: $output = shell_exec('powershell get-service | group-object'); it will not pass the pipe | character but if I try to run: $output...

'unexpected token' in PowerShell when fully pathing executable.

Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive. # My path includes pscp so this works. pscp.exe -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HOST}:${PROXY_DIR} # This does not work. I get unexpected token error. Why? What does tha...

Powershell .CopyHere if it already exists work around

Hi, I run the following to unzip and want to over write the current files if they exist but the microsoft solution found here(http://msdn.microsoft.com/en-us/library/ms723207%28VS.85%29.aspx) doesn't seem to work. I haven't found anything that says it works so is there a work around to select the 'yes to all' option? $zipPackage = (ne...

PHP to Powershell using shell_exec

If I run: $output = shell_exec('powershell "get-service "dhcp""'); I get perfect output of the service dhcp showing running but if I run: $output = shell_exec('powershell "get-user "testing""'); I get nothing. I don't see any difference in what Im doing here - and why get-service would work but get-user would not. If I run it...

TFS - Get a changeset range

Every release I find it a good practice to go back and grab all the changeset notes to compare to the release notes to make sure we didn't miss anything. Since we have a blurb of all feature changes pretty well documented in the changeset notes, they're a valuable resource. What I haven't found is a good way to extract these from TFS 2...

calling web service from .net app

i added web service as reference to a project and gave it name "days". but i dont actually understand how to work with it. can someone show me the way how to get data from it. in posh i get data from web service this way: $ws= New-WebServiceProxy -uri $xmld.Root.WebService.Address -credential $cred $xml = $ws.getdays() $xml ...

How to pause a Powershell script until some external event has occurred?

I am using a Powershell 1 script to kick off a Python program, and I want to then pause the Powershell until the Python has completed its work. (I have complete ownership of the Python file.) What is the best way to go about this? ...

Get Mail by Subject with mail.dll in Powershell

Trying to Read a string in Powershell from an email with IMAP connect: I use the Mail.dll from http://www.lesnikowski.com/mail/ Docu: http://www.lesnikowski.com/mail/documentation/ I want to search for a specific Subject. What i have so far: [Reflection.Assembly]::LoadFile("c:\mail.dll") $imap = new-object Lesnikowski.Client.IMAP.Ima...

Getting character count for each row in text doc with Powershell

I am trying to get the character count for each row in a text doc. The contents of my text doc are: 1 15 69 124 300 I've been trying variants of the PS script: get-content c:\serverlist.txt | foreach-object {measure-object -character} But the best I can get returned is: Lines     Words     Characters   Property -------     --------...

PowerShell MAML Help Generator

Does anyone know of a utility for generating PowerShell cmdlet help files? Doing it by hand seems a bit tedious... I located: http://blogs.msdn.com/powershell/archive/2007/09/01/new-and-improved-cmdlet-help-editor-tool.aspx Any updated versions? I can't select a module. I have a binary module. ...

Error trying to loop through $args in script file using range notation for loop index

I can't figure out why the following code fails: # test.ps1 "`$args: ($args)" "`$args count: $($args.length)" # this fails 0..$($args.length - 1) | %{ $args[$_] = ($args[$_] -replace '`n',"`n") } # this works $i = 0 foreach ( $el in $args ) { $args[$i] = $args[$i] -replace '`n',"`n"; $i++ } "$args" I'm calling it like so: rem from ...

Powershell's import-clixml from string

Is there any way to run import-clixml cmdlet on a string or xml object? It requires a file path as input to produce ps objects and can't get input from an xml object. Since there is convertto-xml cmdlet which serializes ps object into xml object, why isn't there a convertfrom-xml, which would do the opposite? I am aware of System.Xml.Ser...

T-SQL results to .txt file , send alert if null? From powershell script...

Disclaimer: i still suck at writing scripts please be gentle if this is a dumb question! :) What i'm doing is pretty simple. I am using a SqlServerCmdletSnapin which gives me the ability to run t-sql queries in powershell 1.0 and return it to either the console or a out-file. I am currently sending it to a .txt file, my code so far is h...

PowerShell, formatting values in another culture

Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses . as a decimal separator, while PowerShell honors my locale settings (de-DE) when converting floating-point numbers to strings. Is there an easy way to set another locale f...

How can I get warning output from a PowerShell cmdlet programatically in v1.0?

Hi, I'm using PowerShell v1.0 (It is a requirement that I cannot use 2.0) and am having trouble trying to programatically capture the cmdlet output in the Warning stream. In Powershell 2.0 it's easy: var powerShell = PowerShell.Create(); powerShell.AddCommand(someCommand); powerShell.Invoke(); foreach (var warning in powerShell.Strea...

Sql Command (Exception calling "ExecuteScalar" with "0" argument)

When I run the below code on first attempt I get an unexplained error, but running the script again on a second attempt works fine...what would be wrong in my code? By the way I am creating the database before this step... $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=$dBS...

Why did a PowerShell script argument need to be copied to a local variable?

I have a very simple Powershell v1.0 script to kill processes by name: $target = $args[0] get-process | where {$_.ProcessName -eq $target} | stop-process -Force which works. However, when I just had get-process | where {$_.ProcessName -eq $args[0]} | stop-process -Force it wouldn't find any processes. So why does the argument need ...