Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - calling winrm from a custom cmdlet

Reply
 
Old 05-15-2008   #1 (permalink)
Simon


 
 

calling winrm from a custom cmdlet

Hi,

I am trying to write a cmdlet as part of a PSSnapin (in C#) that calls
winrm and then prints the output back on the console. For example, I
have a cmdlet called Get-AvailableX, which would take some input
parameters and transform them into an argument string to pass to a
winrm enumerate call (in this case, to enumerate all instances of X).
I would then like all of the returned instances printed out on the
powershell console.

The only way I have discovered to do this so far is using the
System.Diagnostics.Process class, but when I try that, I keep getting
exceptions saying "The system can not find the file specified".

I am simply trying the following (where args is a string I constructed
beforehand):
System.Diagnostics.Process.Start("winrm.cmd " + args);

If I type 'winrm' on the powershell console I get back the expected
results. Any ideas why I can't get it going through my C# code?

Thanks,

Simon

My System SpecsSystem Spec
Old 05-15-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: calling winrm from a custom cmdlet

Quote:

> I am simply trying the following (where args is a string I constructed
> beforehand):
> System.Diagnostics.Process.Start("winrm.cmd " + args);
>
> If I type 'winrm' on the powershell console I get back the expected
> results. Any ideas why I can't get it going through my C# code?

I don't know what kind of environment will be inherited by the host, but
how about trying the full path just for fun:

[System.Diagnostics.Process]::Start("C:\WINDOWS\system32\winrm.cmd")

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
winrm invoke a custom action PowerShell
winrm connection to custom web service PowerShell
Could not load type when executing a custom cmdlet PowerShell
Custom cmdlet suite best practices: pipe .NET objects? ...or XmlDocuments? PowerShell
[Ann] Format-Graph custom CmdLet to display graphics within PowerShell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46