powershell

How can I load WPFToolkit assembly in Powershell

I have installed WPF Toolkit: Location: C:\Program Files\WPF Toolkit\v3.5.40320.1\WPFToolkit.dll Name: WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Type: Library I can load it by full path: [System.Reflection.Assembly]::LoadFrom("C:\Program Files\WPF Toolkit\v3.5.40320.1\WPFToolkit.dll") But c...

Can not add rows to WPF DataGrid in PowerShell

I am using DataGrid from "WPF Toolkit" from PowerShell. The problem is that I can't add new rows using GUI. dialog.xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:dg="clr-namespace:Micro...

Exception automating Excel 2007 with Powershell when calling Workbooks.Add()

The following code throws an exception in Powershell V1 (Excel 2007): $E = New-Object -COM "Excel.Application" $E.Visible = $True $wb = $E.Workbooks.Add() #<<<Exception here The error says that the format might be old or that the type library is not valid (translated from Spanish). A similar script for Word works just fine. ...

Powershell . Declare generic list with class defined using 'Add-Type'

I am trying to declare List in PowerShell, where the Person is defined using Add-Type: add-type -Language CSharpVersion3 -TypeDefinition @" public class Person { public Person() {} public string First { get; set; } public string Last { get; set; } } "@ This works fine: New-Object Person New-Object...

PowerShell WPF DataGrid: Exception thrown commiting emtpy row

I get exception trying to commit empty DataGrid row. System.NullReferenceException: Object reference not set to an instance of an object. at MS.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid() at MS.Internal.Data.PropertyPathWorker.get_IsDBNullValidForUpdate() at MS.Internal.Data.ClrBindingWorker.get_IsDBNullVal...

PowerShell "Advance" parsing to calculate components installation time based on log file

Hi, i have an application that create a log file of the following format: 2009-03-27 15:30:50 Start 2009-03-27 15:30:51 Starting Component 1 Installation 2009-03-27 15:30:52 blah 2009-03-27 15:30:53 blah 2009-03-27 15:30:54 blah 2009-03-27 15:30:55 ~~~ Finished Component 1 Installation ~~~ 2009-03-27 15:30:56 Starting Component 2 Insta...

PowerShell converts values returned from function. How to avoid this?

I am trying to return List< T> from PowerShell function, but get one of: null - for empty list System.Int32 - for list with one element System.Object[] - for list with more elements Code: function CreateClrList { $list = New-Object "System.Collections.Generic.List``1[System.Int32]" $list.Add(3) $list } Write-Host (Creat...

How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell?

How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer? That is, if I have Internet Explorer open in multiple windows, how do I associate the COM object corresponding to one of those windows with a variable in Powershell, from within Powershell? The closest I have come to doing thi...

Can't start debugger in PowerGUI

I am using the PowerGUI Script Editor 1.7.1.702, and trying to start debugger, but I get such error message: Cannot find a provider with name 'Remove-PSBreakPoint -BreakPoint $bE4078E3092DF4dd9A469F3DC0CBB505C;Remove-Variable vE4078E3092DF4dd9A469F3DC0CBB505C;Remove-Variable bE4078E3092DF4dd9A469F3DC0CBB505C; This happens o...

PowerShell: echo equivalent in script testing

This is probably a very obvious question.. I would like to output variables and values out in a PowerShell script by setting up flags and seeing the data matriculate throughout the script. How would I do this? For example, what would be the PowerShell equivalent to this PHP: echo "filesizecounter : " . $filesizecounter ? ...

Reflection with Powershell

I have a set of .NET Assemblies (all under the same directory) and some of those contain classes which implement an abstract class. I would like a Powershell script to find all the classes which implement my abstract class, and execute a method on each of them. Does anybody have an idea on how to do this? Thanks! ...

Using Powershell to Generate Report of C# Classes versus Methods and Properties

Has anyone used Powershell to generate a report of C# classes versus methods and properties? I'll admit up front I'm not attempting first to write this myself, but someone out there has probably already done it, or would highly enjoy doing it. The challenge will be recognizing things like method signatures across multiple lines. You c...

Sorting Powershell Version

In PowerShell if i have a list of strings containing versions "3.0.1.1","3.2.1.1" etc how can I Sort it the way System.Version would sort it in c# ...

Flatten array in PowerShell

Assume we have $a = @(1, @(2, @(3))) I whould like to flatten $a to get @(1, 2, 3) I have found a solution @($a | % {$_}).count But may be there is a more elegant way? ...

Out-File -force, Intermediate directories are not created

My code is: $path = "c:\no-such-dir\00.txt" "foo" | Out-File -force -filePath $path The error: Out-File : Could not find a part of the path 'C:\no-such-dir\00.txt' help out-file -full For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to cha...

Setting windows powershell path variable

So I've found out that setting the PATH environment variable affects only the old command prompt, powershell seems to have different environment settings. How do I change the environment variables for powershell (v1)? Note: I want to make my changes permanent, so I don't have to set it every time I run powershell. Does powershell have ...

Advice for Windows XP Scripting, WSH versus PowerShell

After much experience scripting in the Unix/Linux open-source world, using languages such as Bourne Shell, Perl, Python, and Ruby, I now find myself needing to do some Windows XP administration scripting. It appears that the legacy environment is Windows Script Host (WSH), which can use various scripting languages, but the primary langua...

Unix newlines to windows newlines (on Windows)

Does anyone know of a way (say Powershell, or a tool) in Windows that can recurse over a directory and convert any unix files to windows files. I'd be perfectly happy with a way in Powershell to at least detect a unix file. It's easy do this for one single file, but I'm after something a bit more scalable (hence leaning towards a Power...

How can I know that PowerShell function parameter is omitted

Consider such function: function Test($foo, $bar) { ... } We can call it: Test -foo $null Test How can I know when the -foo was omitted, and when it was $null? ...

How to omit $null arguments calling a function?

Consider such function: $missed = "{716C1AD7-0DA6-45e6-854E-4B466508EB96}" function Test($foo = $missed, $bar = $missed) { if(!$foo) { throw "error" } if(!$bar) { throw "error" } } I whould like to call this function this way Test -foo $foo -bar $bar But if $foo or $bar is $null, exception will be thrown. The ...