Posts Tagged ‘C#’

Decompiling C# Code with ILSpy and PowerShell

This week at the PowerShell Summit in Redmond, I gave a talk about using .NET reflection in PowerShell. We took a quick look at ILSpy and how to read the decompiled C# code that makes up compiled .NET assemblies. After a comment by Karl Prosser, I figured it would be cool to take it a […]

PoshInternals – Install-BlueScreenSaver

Bluescreen is a screen saver that is part of the SysInternals suite that mimics a Windows blue screen of death. It can also mimic chkdsk and the boot process. Screen savers themsevles are actually just executable files renamed with an extension “scr”. Once placed in the System32 or SysWow64 directory, they can be accessed via […]

Pseudo-Polymorphism in PowerShell

When learning a strongly-typed, object oriented language one of the first concepts you learn is polymorphism. Polymorphic members accept object types that define a particular contract. Class instances that meet this contract, even if they extend from it, can be provided to these members. In PowerShell, this can be true when dealing with .NET classes. […]

Hooking a Remote Process and Stealing a Password in PowerShell

In my last post we looked at how to hook the local PowerShell process and adjust the date by hooking the GetSystemTimeAsFileTime WinAPI function. This was accomplished using EasyHook, a detouring library similar to Microsoft Detours. In this post I’ll show you how to hook a remote process and inject our own implementation of a […]

Using Roslyn and PowerShell 3 to Convert C# to PowerShell

Right after seeing Jason Bock’s Roslyn session at That Conference I wanted to combine the two abstract syntax tree systems to do something like this. I haven’t finished a full working copy but anticipate making something that is usable via the command line or other projects in DLL form. With Roslyn, one of the samples creates a […]

Tandem PowerShell Sessions

This is more of a concept than an actual implementation. I usually like to have something working before blogging about it but summer time is making it hard to get things done! A couple of my co-workers are windbg gurus. One day they were working on something and it just blew my mind! They were both […]

Creating a PowerShell Profiler

In my last post I talked about the AST and how it was now possible to modify it using the visitor pattern. After talking to some of the Microsoft folks at the PowerShell Deep Dive, the idea was suggested that this would allow for the creation of a profiler for PowerShell scripts. I had written […]

PowerShell AST Modification

As I’ve mentioned in a few posts the AST is now public in PowerShell 3.0. Each node in the AST derives from the AST class which in turn implements the Visit method. The Visit method accepts an ICustomAstVisitor instance that is used to visit the different nodes within the AST. This gives us a chance […]

Using Dynamics To Call PowerShell in C#

In PowerShell 3.0 all PSObjects are now based on the dynamic language runtimeDynamic Runtime Library. Joel Bennett has a great article about what that means to PowerShell. For a C# developer this is also a pretty neat. In the past this is how PSObjects were accessed in C#. foreach(var process in PowerShell.Create().AddCommand("Get-Process").Invoke()) { Console.WriteLine(process.Properties["ProcessName"].Value); } […]

Building Binary PowerShell Modules – Part 2 – Design Principles and Other Guidelines

I had anticipated that I would be writing this second part about providers rather than design principles, but after listening to a recent Powerscripting Podcast I thought it would be helpful for me to provide a few things I’ve learned from developing the vWorkspace PowerShell module. Many of the points brought up during the podcast […]