header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
What is this funky syntax?
Last Post 18 Apr 2011 05:37 AM by halr9000. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
LMizuhashiUser is Offline
New Member
New Member
Posts:24
Avatar

--
17 Apr 2011 02:55 PM
    Hey all,

    I'm new to this forum, PowerShell and the .NET Framework. All of my previous work had me using Linux, Apache, MySQL and PHP--all the good, free stuff of the world.

    I'm writing a simple library of scripts at work that will occasionally poll a couple of subnets in our office for certian tidbits of basic information. The info we'll be looking for is stuff like the following:
    • Applications installed
    • Printers installed
    • Service Tag Numbers
    And so on.

    Most of the information we need to gather can be accessed through Windows Management Interface (WMI) Objects. The occasional piece of info needs to be retrieved from the registry of a remote computer.

    I found the below lines of code on the web; they accomplish this task of reading the values of remote keys and have gotten them to work in our program:

    $strMachineName = 'MURBAMEXV004'
    $objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
    $objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program" )
    $objRegKey.GetValue("PrimaryScriptServer")


    My question is--where does this funky syntax come from, this [object.subobject.attribute]::method('arguments') stuff?

    Does this come from C# or VBScript or is it merely a standard way to write scripts that play with .NET objects and methods?


    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    17 Apr 2011 04:36 PM
    This syntax comes from .NET. More specifically in this case, it is the syntax required to call a "static method" from .NET from within PowerShell.

    To ease your pain, this might help:
    http://archive.msdn.microsoft.com/P...teRegistry
    LMizuhashiUser is Offline
    New Member
    New Member
    Posts:24
    Avatar

    --
    18 Apr 2011 03:34 AM
    Thank you, Macro!
    That module looks mighty tasty. I might have it with pancakes and syrup this morning. =P

    I'd also like to learn more about interacting with .NET objects in PowerShell; they really seem to be what puts the Power in *Shell for my needs. (I don't mind if it means learning a whole ton about Windows application development; I am that kind of nerd.)

    Can you suggest any good places for a nerd to start learning about interacting with .NET objects directly from PowerShell?
    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    18 Apr 2011 05:37 AM
    I recommend checking out the PowerShell Cookbook 2nd Ed. from O'Reilly. Treasure trove of examples.
    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer