Solved

.framework class powershell remote machine

Posted on 2014-03-24
7
305 Views
Last Modified: 2014-03-27
Hi Guys,

I can't seem to use the -computer switch in powershell when I type a .net frame class e.g :

[System.Environment]::MachineName

[System.Environment]::OSVersion

[System.Environment]::GetEnvironmentVariables()

how can I do this - run these commands on a remote machine?

Also how can I retrieve a list of all that's available under the system class?

thank you in advance.
0
Comment
Question by:Kay
  • 4
  • 3
7 Comments
 
LVL 39

Assisted Solution

by:footech
footech earned 500 total points
Comment Utility
Parameters like -computername are a feature of specific cmdlets in PS.  Not all cmdlets have that parameter as it wouldn't make sense.  Neither would it make sense for all (or any?) types/classes to be able to reference a remote machine.

Your best option (IMO) for running these on a remote machine is PS Remoting.  Actually, I don't think I see any other option.

If you need to see all the static methods and properties available for a class run something like the following:
[system.environment] | gm -static

Open in new window

Is that what you're referring to?  Also, in case you're not aware, gm is an alias for Get-Member.
0
 

Author Comment

by:Kay
Comment Utility
thank you, I wanted to include .net framework classes in a script, and there are multiple servers in question.

I have heard that cmdlets are actually .net framework classes, so I am wondering could there be a way to create a new cmdlet in .net and include the -computer switch?/
0
 
LVL 39

Assisted Solution

by:footech
footech earned 500 total points
Comment Utility
I really haven't studied it at such a low level.  There are so many .Net Framework classes - I'm not sure what you mean by you wanted to include them in a script.
I have heard that cmdlets are actually .net framework classes
I haven't heard that.  I can't say it isn't true, but it doesn't sound right.  Cmdlets are written in C# if I remember right, and though I'm sure they include references to .Net classes, I feel there's more to it than that.  It's definitely possible to write your own cmdlet (if you know how) and include whatever functionality you want.  However, unless you have the skills and desire to be a PowerShell developer, I would recommend that you use the functionality that is already there (as I mentioned, PS Remoting seems to fit the bill here).
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Kay
Comment Utility
thanks, problem with psremoting is that it has to enabled on every server, and I don't know if there is a quick way to do it without manually having to log into each one?

yea I really want to learn automation at an advanced level, therefore it seems like I need to lean c#.net too to become an expert.
0
 

Author Comment

by:Kay
Comment Utility
so powershell developers make the cmdlets right for applications? example powercli used for VMware, would have been written by a powershell developer, the netapp storage also has a powershell module and this again would having been written by a powershell developer?
0
 

Author Comment

by:Kay
Comment Utility
is the powercli module for vsphere written using c#?
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
I'll try to answer your posts in order.

You can enable PS Remoting with Group Policy.  There's only two or three settings (depending on environment) that need to be configured.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/24/an-introduction-to-powershell-remoting-part-two-configuring-powershell-remoting.aspx
You can automate a ton without writing your own cmdlets.  It depends on what you want to do.

I believe so, yes. (in answer to your last two posts)
I am not a PS developer, I'm a scripter, so there's little I could tell you about the developer side.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now