powershell

Powershell, ftp, get-childitem

Hey all, Little new to powershell. I am trying to locate a get-childitem like command that will work on an ftp site. Here is some psuedo-code: $target = "c:\file.txt" $username = "username" $password = "password" $ftp = "ftp://$username:$password@myftpsite" $webclient = New-Object System.Net.WebClient $uri = New-Object System.Uri(...

Using wildcards for filenames in powershell

I am having a lot of issues trying to automate downloading from an ftp site. I know the folder the file will be in, and I know that it will be a .zip file. However I do not know what the files will be named. So I have code that works if I know the file name...for example: $sourceuri = "ftp://myFtpSite/test/myZipFile.zip" I would ...

After install of VS 2010, many powershell scripts broken

I recently upgraded to VS 2010. Shortly after I noticed many powershell scripts I had written in the past no longer worked correctly. I am guessing that its because of .NET 4. Is there any way to fix this, or force powershell to use the older .NET? Thanks for any help anyone can provide. ...

Why is my PowerShell multi dimensional array being interpreted as a 1 dimensional array?

I have the following code: function HideTemplates($File, $Templates) { foreach ($Template in $Templates) { Write-Host $Template[0] $Template[1] $Template[2] } } HideTemplates "test.xml" @(("one", "two", "three")) HideTemplates "test.xml" @(("four", "five", "six"), ("seven", "eight", "nine")) It prints: o n e t w o t h r fo...

Default value list for pipeline param in Powershell

I have a Powershell script that reads values off of the pipeline: PARAM ( [Parameter(ValueFromPipeline = $true)] $s ) PROCESS { echo "* $s" } Works just fine: PS > my.ps1 foo * foo I would like the script to have list of default values, as the most common usage will always use the same values and storing them in...

how to use expressons as function parameters in powershell

This is a very simple task in every language I have ever used, but I can't seem to figure it out in PowerShell. An example of what I'm talking about in C: abs(x + y) The expression x + y is evaluated, and the result passed to abs as the parameter... how do I do that in PowerShell? The only way I have figured out so far is to create ...

How do I get back results running a VB Script from C#?

I want to be able to call VB scripts from C#, which is easy enough, but I need to be able to get back the results from these scripts at times. Should I use the method referenced with something to read back, or should I use a different method? I've found a method to getting data back from powershell scripts using Runspaces and Pipelines...

Powershell / .Net: Get a reference to an object returned by a method

I am teaching myself PowerShell by writing a simple parser. I use the .Net framework class Collections.Stack. I want to modify the object at the top of the stack in place. I know I can pop() the object off, modify it, and then push() it back on, but that strikes me as inelegant. First, I tried this: $stk = new-object Collections.Sta...

How do I get the current Cmdlet from another object?

What's the best way to get the current PowerShell Cmdlet from another object? If I create a helper object that is not a Cmdlet but will be called by Cmdlets, the helper methods may want to call WriteVerbose, WriteDebug etc. What's the best way to get access to that? Is there a static PowerShell method that will return the current Cmdl...

Powershell 2.0 - Running scripts for the command line call vs. from the ISE

Hi, After writing deployment scripts from within the ISE, we need our CI server to be able to run them automatically, i.e. from the command line or via a batch file. I have notice some significant differences between the following calls: powershell.exe -File Script.ps1 powershell.exe -Command "& '.\Script.ps1'" powershell.exe .\Script...

Text piped to PowerShell.exe isn't recieved when using [Console]::ReadLine()

I'm getting itermittent data loss when calling .NET [Console]::ReadLine() to read piped input to PowerShell.exe. In CMD, run: >ping localhost | powershell -NonInteractive -NoProfile -C "do {$line = [Console]::ReadLine(); ('' + (Get-Date -f 'HH:mm :ss') + $line) | Write-Host; } while ($line -ne $null)" 23:56:45time<1ms 23:56:45 23:56:46...

Input encoding : accepting UTF-8

Hi! I need to get output of native application under PowerShell. The problem is, output is encoded with UTF-8 (no BOM), which PowerShell does not recognize and just converts those funky UTF chars directly into Unicode. I've found PowerShell has $OutputEncoding variable, but it does not seem to affect input data. Good ol' iconv is of no...

PowerShell: Retrieve a specific internal XML element

Hi, I have an XML document with this structure: <Fruits> <Fruit> <Code>1</Code> <Name>Apple</Name> </Fruit> </Fruits> What is the best way to get a <Fruit> element by its code (or any other field) in PowerShell 1 code? (Not XPath, as it is supported in PowerShell 2 only) Thanks! ...

What is Get-Command -CommandType Script?

What is Get-Command -CommandType Script? What kind of commands does it cover? Help about Script tells “-- Script: Script blocks in the current session.” but I am not sure what kind of script blocks it means. Are there cases when Get-Command -CommandType Script actually returns anything? ...

Can Win32_NetworkAdapterConfiguration.EnableStatic() be used to set more than one IP address?

I ran into this problem in a Visual Basic program that uses WMI but could confirm it in PowerShell. Apparently the EnableStatic() method can only be used to set one IP address, despite taking two parameters IP address(es) and subnetmask(s) that are arrays. I.e. $a=get-wmiobject win32_networkadapterconfiguration -computername myserver ...

PowerShell - Shorten namespace names so it's easier to access types

Is there a method of shortening PowerShell namespace references? Typing [RootNameSpace1.NameSpace2.Namepsace3+SomeEnum]::SomeValue is taxing and not a very good user expierence. I realize that you can reference System level objects without a namespace such that [Type]::GetType(... will work. Is there some manifest I could create or comm...

Where can I get the Microft SharePoint assemblies?

Hi, I am trying to workup an automated tool for SharePoint interaction through a Powershell script. Am running into a SharePoint.dll not found issue and upon looking it up(including previous posts in StackOverflow), it seems its available in the server. I do not have access to a Sharepoint installation at the moment. Is there some place...

PowerShell: Read text, regex sort, write output to file and formatting

I am a Powershell novice and have run into a challenge in reading, sorting, and outputting a csv file. The input csv has no headers, the data is as follows: 05/25/2010,18:48:33,Stop,a1usak,10.128.212.212 05/25/2010,18:48:36,Start,q2uhal,10.136.198.231 05/25/2010,18:48:09,Stop,s0upxb,10.136.198.231 I use the following piping construct ...

Why can't i call Contains method from my array?

Arrrg!I am running into what i feel is a dumb issue with a simple script i'm writing in powershell. I am invoking a sql command that is calling a stored proc, with the results i put it a array. The results look something like this: Status ProcessStartTime ProcessEndTime ...

How to prevent command/script from changing global environment

I need to run scriptblocks/scripts from the current top-level shell and I want them to leave the global scope unmodified. So far, I've only been able to think of the following possibilities: powershell -file <script> powershell -noprofile -command <scriptblock> The problem is, that they are very slow. For instance, I would like to...