Accessing .NET components from Powershell - powershell

I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work. This is in place of writing a small console app to tie the calls together. My question is where I would find a good source of documentation or tutorial material to help me fast track this?

If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly.
[void][System.Reflection.Assembly]::LoadFrom(PathToYourAssembly)
After you load your assembly, you can call static methods and create new instances of a class.
A good tutorial can be found here.
Both books mentioned by EBGreen are excellent. The PowerShell Cookbook is very task oriented and PowerShell in Action is a great description of the language, its focus and useability. PowerShell in Action is one of my favorite books. :)

The link that Steven posted is a good example. I don't know of any extensive tutorial. Both the Windows Powershell Cookbook and Windows Powershell In Action have good chapters on the subject. Also, look at the ::LoadFromFile method of the System.Reflection.Assembly class in case your in-house assemblies are not loaded in the GAC.

you can use [] or use add-type -AssemblyName "System.example" to use assembly for example use :
[system.drawing]::class ...

Related

Determine in what module a class resides

I have some code that works a treat in the ISE, but fails in a script. It fails where I use [System.Windows.Media.GlyphTypeface]::new(), and this is a common occurrence, a module that is loaded automatically in the ISE, but needs to be loaded discretely in a script.
So that brings up the generic question, is there a way to start from the type and determine what module is needed? Or is this one of those where you just need to already know and/or be able to mine the Microsoft support documents for the info?
System.Windows.Media.GlyphTypeface is not a PowerShell module. It is a .NET Framework class. You generally will need to check the documentation for the class to find the Assembly it belongs to. (https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.glyphtypeface) In this case PresentationCore.dll.
You would use AddType to load this assembly.
Add-Type -AssemblyName PresentationCore
A search for "find .net assembly from class name" will find some Q&A on this topic, but mostly with C# examples.

Ansible CallbackBase result object content

Our dev team provides us an Ansible package to work with. I noticed thy develop a custom stdout_callback and I'm trying to understand it.
I'm looking at the code of the class CallbackBase available here and I noticed the result variable but I can't find a description of it's content.
Is there a place I can find such information?
Next question, how does Ansible call such callback? CallbackBase contains several methods but I'd like to know where those methods are called.
Thanks for your feedbacks

BMC Remedy User (WMSTI): Macro Language?

I need to know the language, which is used in BMC Remedy User (WMSTI) macros? The tool is called 'BMC Remedy User' (WMS-TI within the company (Telekom)).
Here are some code snippets from the macros which are standardly implemented:
Form-open:
Form-entry-list: 0
Form-final: modify#
end
and another snippet:
[wordrecord]
Path=C:\Program Files\Microsoft Office\OFFICE12\winword.exe
Application=winword
Topic=system
Format=Record
CharsPerLine=100
XFRDATA=Clipboard
Command1=[FileNew .Template="Normal", .NewTemplate = 0]
Command2=[Editpaste]
What kind of language is this and is there any learning material?
BMC Remedy User tool is not supported but developer can install it locally to ease their work.
apart from this, have a look on-https://communities.bmc.com/docs/DOC-28466
Remedy User Tool macro language is proprietary.
Since Remedy User Tool is not supported anymore, I'd encourage you to use updated technologies, like SOAP or REST (for everything back-end), or AngularJS (for everything front-end)
Another solution would be to use tools created by the Remedy Community, like the one appearing on https://communities.bmc.com/message/437693#437693

Are there any other examples of DSL in powershell?

PowerBoots is a very useful example of DSL which exploits script blocks to create GUIs:
Boots {
StackPanel {
Button "A bed of clams"
Button "A coalition of cheetas"
Button "A gulp of swallows"
}
}
I know that without specifying a target Domain this question appears very general. So I'm going to make it more specific:
Do you know any other project implementing a kind of DSL in powershell?
You should also look at psake: https://github.com/JamesKovacs/psake
Also, I just found Pester, which is the PoSh answer for RSpec: https://github.com/pester/Pester
Another example: Windows PowerShell: A Better XML
Here's an example of a DSL for XML in PowerShell. Here's a blog post by Jeffrey Snover about DSLs in PowerShell (look at the comments for more links).
I tried PowerShell as DSL script for a C#.Net application and my experience has posted here. .PowerShell is really powerful when it comes to DSL world.

MonoTouch iPhone: Creating native assembly .NET wrappers

We are considering using an API from a 3rd party for the iPhone which was compiled in Xcode.
How do we create a wrapper for this native iOS library so that we can interop with it in Monotouch .NET
This is exactly what the Flurry.a wrapper did. We need to find out how to do it ourselves though. See Kevin Machanon's http://blog.kevfoo.com/index.php/2010/08/monotouch-flurry-analytics-bindings
On Kevin Machanon's GitHub repository you can take a look at the actual code. At first sight I believe the process implies the creation of an interface that mimics the native class you would like to use and decorate it with mapping attributes:
BaseType
Static
Export
And pass the detailed native method call to the attributes parameters.