Solved

.framework class powershell remote machine

Posted on 2014-03-24
7
316 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 40

Assisted Solution

by:footech
footech earned 500 total points
ID: 39950016
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
ID: 39950353
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 40

Assisted Solution

by:footech
footech earned 500 total points
ID: 39950809
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:Kay
ID: 39950913
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
ID: 39950920
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
ID: 39950924
is the powercli module for vsphere written using c#?
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39950973
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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