Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I use System.IO.Pipes with PowerShell CTP2

92 views
Skip to first unread message

RickB

unread,
Oct 13, 2008, 1:56:39 PM10/13/08
to
Perhaps this should really be a broader question.
Can I use .net 3.5 functionality under CTP2?

RichS [MVP]

unread,
Oct 13, 2008, 4:45:27 PM10/13/08
to
Yes - for instance see my posts on using
System.DirectoryServices.Accountmanagement classes

for instance

http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1360.entry

--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

RickB

unread,
Oct 13, 2008, 5:24:32 PM10/13/08
to
On Oct 13, 3:45 pm, RichS [MVP] <RichS...@discussions.microsoft.com>
wrote:

> Yes - for instance see my posts on using
> System.DirectoryServices.Accountmanagement classes
>
> for instance
>
> http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1360...

>
> --
> Richard Siddaway
> All scripts are supplied "as is" and with no warranty
> PowerShell MVP
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
>
>
> "RickB" wrote:
> > Perhaps this should really be a broader question.
> > Can I use .net 3.5 functionality under CTP2?- Hide quoted text -
>
> - Show quoted text -

Thank you.

There were several things I was doing wrong.

This should get anyone else started on the right foot.

There are async facilities that can be used too but the sync versions
show the timing dependencies better.

# This is the 3.5 assembly you need to load
[Reflection.Assembly]::LoadWithPartialName('System.Core')

# server side tasks
# A client connect will hang until a server side is created.
$a = new-object System.IO.Pipes.NamedPipeServerStream('TestPipe')
# This will hang until a client connects
$a.WaitForConnection()
# Create a byte array for input message
$msg = new-object byte[] 1000
# This will hang until client writes
$cnt=$sv.read($msg,0,$msg.count)
# Convert byte array back to string.
[string]::join('',[string[]][char[]]$msg[0..($cnt-1)])

# Client side tasks
$b = new-object System.IO.Pipes.NamedPipeClientStream('TestPipe')
# Connect hangs until a NamedPipeServerStream is created (above).
$b.connect()
# The message to send must be a byte array, not a string.
[byte[]]$txt=[char[]]'some message I want to send'
# The write will hang until the server reads it.
$rq.write($txt,0,$txt.count)

Marco Shaw [MVP]

unread,
Oct 13, 2008, 8:40:13 PM10/13/08
to
RickB wrote:
> Perhaps this should really be a broader question.
> Can I use .net 3.5 functionality under CTP2?

A broader answer: It can depend...

Example, from what I understand, you can use some of the features of
LINQ (.NET 3.5) directly from PowerShell. Also, until v2 CTP2, using
WPF (.NET 3.0) in PowerShell had issues.

Marco

--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

RickB

unread,
Oct 14, 2008, 8:04:16 AM10/14/08
to
On Oct 13, 3:45 pm, RichS [MVP] <RichS...@discussions.microsoft.com>
wrote:
> Yes - for instance see my posts on using
> System.DirectoryServices.Accountmanagement classes
>
> for instance
>
> http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1360...

>
> --
> Richard Siddaway
> All scripts are supplied "as is" and with no warranty
> PowerShell MVP
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
>
>
> "RickB" wrote:
> > Perhaps this should really be a broader question.
> > Can I use .net 3.5 functionality under CTP2?- Hide quoted text -
>
> - Show quoted text -

Thanks to both of you.

I never did get the async stuff to work.
Best I can tell, from reading various threads on async callbacks
in PowerShell, the async features are unuseable from PowerShell.

It seems that, theoretically, background jobs running the sync
versions should work. Before I spend hours trying, is this the
only way or is there a better way?

Oisin (x0n) Grehan [MVP]

unread,
Oct 15, 2008, 10:27:52 AM10/15/08
to
> only way or is there a better way?- Hide quoted text -

>
> - Show quoted text -

Hi Rick,

You seem to be a fairly technical guy - have you looked into CTP2's
eventing support?

http://blogs.msdn.com/powershell/archive/2008/06/11/powershell-eventing-quickstart.aspx

- Oisin

RickB

unread,
Oct 15, 2008, 1:06:06 PM10/15/08
to
On Oct 15, 9:27 am, "Oisin (x0n) Grehan [MVP]" <ois...@gmail.com>
wrote:
> http://blogs.msdn.com/powershell/archive/2008/06/11/powershell-eventi...
>
> - Oisin- Hide quoted text -

>
> - Show quoted text -

I've been meaning to look into that but forgot. Thanks. It turns it
may be very helpful to another project. I hope it works in our
environment. With all our machines being either XP or Server 2005 I
can't use jobs or runspaces under CTP2.

Unfortunately I couldn't figure out how eventing could help with named
pipes. The async features use methods that expect a callback
function. They don't create events I can subscribe to. Is there a
loophole? Register-ObjectEvent's -Action argument seems to have a way
around it.

Otherwise I'm hitting dead ends in each direction.

Oisin (x0n) Grehan [MVP]

unread,
Oct 17, 2008, 9:29:55 AM10/17/08
to
> Otherwise I'm hitting dead ends in each direction.- Hide quoted text -

>
> - Show quoted text -

Hi RickB,

I'll show you how you can do this later this evening (EST). Keep an
eye on my blog ( www.nivot.org )

Hint: it involves using the Add-Type and Register-ObjectEvent cmdlets.

- Oisin

PowerShell MVP
http://www.nivot.org/

RickB

unread,
Oct 20, 2008, 10:26:07 PM10/20/08
to
On Oct 17, 8:29 am, "Oisin (x0n) Grehan [MVP]" <ois...@gmail.com>
> PowerShell MVPhttp://www.nivot.org/- Hide quoted text -

>
> - Show quoted text -

I guess you didn't have time (or I'm looking in the wrong place).

The hint didn't help much. Windows isn't my native platform so it
didn't go as far as it might for someone else. It doesn't help
that the commands are not documented either but I'm guessing that
your method will include a piece that starts like this.

add-type @"
using System;
...

But the implications are not landing on live brain cells.

RickB

unread,
Oct 29, 2008, 9:24:00 AM10/29/08
to
On Oct 17, 8:29 am, "Oisin (x0n) Grehan [MVP]" <ois...@gmail.com>
> PowerShell MVPhttp://www.nivot.org/- Hide quoted text -

>
> - Show quoted text -

I am actually beginning to wonder if the hints didn't help
because it's more complicated that it initially seemed.
If the solution is only evident to someone who has interfaced
with PowerShell from C#/VB.Net then it's obvious why I'm
not getting anywhere.

0 new messages