Giter Site home page Giter Site logo

merbla / scriptcs-powershell-module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beefarino/scriptcs-powershell-module

0.0 1.0 0.0 554 KB

allows you to run arbitrary ScriptCS code from your PowerShell session

License: Other

PowerShell 8.34% C# 25.43% Smalltalk 66.22%

scriptcs-powershell-module's Introduction

ScriptCS-PowerShell-Module

This is a PowerShell module that allows you to run arbitrary ScriptCS code from your PowerShell session.

In addition, you can pipe input to and output from ScriptCS.

Building

You will need psake 4.0 to build and install this module.

The following PowerShell script will build the module and install it to your personal module area:

import-module psake;
invoke-psake default.ps1 -task Install

Quick Start

Once the module is built and installed, you can use it like any other PowerShell module:

> import-module scriptcs
> invoke-scriptcs 'DateTime.Now'

Wednesday, May 15, 2013 11:26:58 AM

Pipeline Input

The invoke-scriptcs cmdlet can receive pipeline input. This input is available to your ScriptCS code from the Input property of the pscmdlet object defined automagically:

> 0..9 | invoke-scriptcs 'pscmdlet.Input'

0
1
2
3
4
5
6
7
8
9

Note that pscmdlet.Input is an object[]. If you need to reference members of a more specific type you will need to cast the input in your ScriptCS code. Care should be taken since PowerShell's type system can modify / wrap / extend an object's type without you realizing it. When in doubt, do this to see what you're working with:

> ... | invoke-scriptcs "pscmdlet.Input[0].GetType().FullName"

Pipeline Output

Any data output from the ScriptCS code is written to the pipeline:

> invoke-scriptcs 'DateTime.Now' | get-member

   TypeName: System.DateTime

Name                 MemberType     Definition                                           
----                 ----------     ----------                                           
Add                  Method         System.DateTime Add(System.TimeSpan value)           
AddDays              Method         System.DateTime AddDays(double value)                
...

In addition, the WriteObject method of the pscmdlet object can be used to write data to the pipeline from ScriptCS.

The pscmdlet object

The Invoke-ScriptCS cmdlet defines an object in the ScriptCS space named "pscmdlet" that you can use to access the PowerShell session. This variable is functionally equivalent to the $pscmdlet variable available in PowerShell advanced functions, which you can learn more about here.

scriptcs-powershell-module's People

Contributors

beefarino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.