powershell

Structs or Objects in Powershell 2

Does the latest version of Powershell have the ability to do something like JavaScript's: var point = new Object(); point.x = 12; point.y = 50; If not, what is the equivalent or workaround? UPDATE Read all comments ...

PowerShell - Start-Process and Cmdline Switches

I can run this fine: $msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" start-process $msbuild -wait But when I run this code (below) I get an error: $msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /v:q /nologo" start-process $msbuild -wait Is there a way I can pass parameters to MSBuild using start-...

How do I efficiently pre-pend a line to a large file in Powershell

I have some large files in CSV format that I would like to turn into objects using the Import-Csv command in Powershell. The files are missing the column headings however and these need to be added before I use Import-Csv. What is the fastest and most efficient way of adding these to the file? ...

Where can I find all of the COM objects that can be created in Powershell?

In Powershell I can create COM objects which can be used, for example, to control Microsoft Office applications: $excel = New-Object -com "Excel.Application" $excel.visible = $true How can I list all of the available COM objects that can be created in Powershell? ...

Capturing Non-Standard Powershell CmdLet Output for Flow Control

Currently trying to build a script utilizing cmdlets from the MS released "Team Foundation Server Power Tools" package. I'm attempting to flow command logic from the success or failure of the "Update-TfsWorkspace" cmdlet however I can't seem get a return code out of the call nor can I capture the output using Out-String. I'm using Powe...

Logparser iTsFormat

Hi Guys, This is a weird one, Im using logparser to work through some log files and present some output. The input to logparser is being created by some powershell scripts that Ive written to replace the existing batch files. Heres a sample of the original input files; 10.197.71.26 AU 03172009 23:59:59 21 116490096 As you can see ...

How to use PowerShell Get-Member cmdlet

A newbie question: The command: [Math] | Get-Member Returns all members of System.RuntimeType. Why is that? Also the command: Get-Member -InputObject [Math] Returns all members of System.String. If "[Math]" is interpreted as string here, how can I make it a math object? Also, does Get-member takes any positional parameters? How ...

Powershell writing tabs to a file

I need to echo a series of elements of an array in PS but provide various delimiters between the elements, so Im using; Add-Content -Path $tempInputDir\testoutput.log -value ($($fields[0]) + " "+ $($fields[1]) + " " + $($fields[2]) + " " + $($fields[3])+ " "+ $($fields[15]) + " " + $($fields[17])) } So I need to be able to add...

Powershell expensive parsing

Hi Guys, Heres a little segment from a script Im writing; Get-Content $tempDir\$todaysLog | Where-Object { $_ -match "" } | ForEach-Object -Process { $fields = [regex]::split($_,'@|\s+') Add-Content -Path $importSource2\$todaysLog -value ($($fields[0]) + "`t" + $($fields[1]) + "`t" + $($fields[2]) + " " + $($fields[3])+ "`...

Powershell Copy-Item but only copy changed files...

I am trying to recurse through a directory and copy it from A to B. That can be done with the following: Copy-Item C:\MyTest C:\MyTest2 –recurse I want to be able though to only copy new files (ones that exist in src but not dest) and also only copy files that may have changed based off a CRC check and not a datetime stamp. $file = "...

Using Powershell to Register a file in the Gac

Is there a simpe way to in powershell (I imagine using gacutil.exe) to read from a text document a path\assembly and register it in the GAC? So for example a .txt file that looks like: c:\test\myfile.dll c:\myfile2.dll d:\gac\gacthisfile.dll The powershell script would read that into a stream and then run gacutil on each of those assem...

How do I get Powershell to execute in scheduled task?

I have created a Powershell script and set it up to run within a .bat file. When I click on the .bat file the Powershell script runs like a champ. I then set up the .bat file to be run as a scheduled task. Again it works like a champ when I right click on it and launch it interactively. Problem is it fails when the task scheduled ...

Application Deployment with Powershell

I've developed a Powershell script to deploy updates to a suite of applications; including SQL Server database updates. Next I need a way to execute these scripts on 100+ servers; without manually connecting to each server. "Powershell v2 with remoting" is not an option as it is still in CTP. Powershell v1 with WinRM looks the mos...

Google code search - missed languages

This is very odd, but I don't see neither PowerShell nor XAML among supported languages http://www.google.com/codesearch/advanced_code_search ?! How can I filter results for that languages? ...

Does PowerShell support OOP?

What is about such concepts as Class, Interface, Mixin in PowerShell? Does it support OOP? If so, where can I read about this? ...

Include relative files in PowerShell

I would like to include script files with such pseudo syntax: Include '.\scripA.ps1' But the only thing I have found is some thing like this: $thisScript = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent . ($thisScript + '.\scriptA.ps1') that is ugly. Is there some nice way to include scripts with relative paths? ...

Finding the current active language on windows

What are the possible solutions for finding the current active language which appears on the Windows language bar ? ...

How to pass arguments to function referenced by variable

I have a function 'foo' and a variable '$foo' referencing it. function foo { param($value) $value + 5 } $foo = foo $foo I can call $foo without args, but how can I pass parameters? This does not work: $foo 5 $foo(5) Actually the goal is to write such code: function bar { param($callback) $callback 5 } bar(foo) ...

$macro substitution - ExpandString limitations

I am trying to implement macro replacement based on this discussion. Basically it works, but seems the ExpandString have some limitatoins: main.ps1: $foo = 'foo' $text = [IO.File]::ReadAllText('in.config') $ExecutionContext.InvokeCommand.ExpandString($text) | out-file 'out.config' in.config (OK): $foo in.config (Error: "Encountere...

Can PowerShell be used as code behind for WPF

We can use [Windows.Markup.XamlReader]::Load to load XAML file in PowerShell, but is there some way to specify some PowerShell script as code behind? ...