Solved

Powershell and configuring settings - how to remove a setting?

Posted on 2014-11-04
3
423 Views
Last Modified: 2014-11-06
This is mostly a general question. I'll give an example for the sake of asking this question but this is more about how to "unset" settings from a general sense.

Here's what I mean, and maybe it's just my noob-ness to Powershell or the specific technology, but when I need to configure something, and I google around and find that the only way Windows allows this setting to be configured is via Powershell, and then I find an example command to run to make the intended change.

Just for example's sake, say I needed to set an allowed VLAN list on a virtual machine and set it to trunk mode, and i found this as the command:

Set-VMNetworkAdapterVlan –VMName MY_VM_NAME –Trunk –AllowedVlanIdList 201-230 –NativeVlanId 201


So OK great, I run the command and bingo it's done.

But - what if I later decide I want to revert back? If I just needed to change the allowed VLAN range I know I can just re-run the same command with the new values.

But what if I changed my mind, I don't want an vlan range restriction, and/or I no longer want this in Trunk mode.

Microsoft's help page just gives all the different possible settings:
http://technet.microsoft.com/en-us/library/hh848475.aspx


In a Windows GUI at least you have some way to look at the settings and see what other options there are (dropdown or radio buttons for example).  In Linux in most cases configurations are in a text file that is easily browsed and normally commented.

In Windows, where a setting can only be set via Powershell, I seem to always run into situations where I know that once a make a change this way, I'll have no idea how to revert back if needed.



I guess I'm just looking for some advice on how others deal with this, and how you learn more about the different options.  I know how to get help for a module but then once it's deep in the switches/options I'm not always clear when building a powershell command how to get details on the switch options (from within Powershell), and even if I did it would probably still look similar to technet and not really explain how to reset something back to default.

Any advice or guidance would be appreciated.
0
Comment
Question by:Vas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 250 total points
ID: 40423425
Good morning,

Inside PowerShell you should be able to run (for example):
Get-Help Set-VMNetworkAdapterVlan -Parameter Access

Open in new window

You can see in the description of the particular CmdLet that the different VLAN tagging options are all mutually exclusive, so it should get very upset if you were to try this:
Set-VMNetworkAdapterVlan -VMName MY_VM_NAME -Trunk -Access

Open in new window

To revert the change you would, of course, need to be aware of the previous setting. But the options are there in the CmdLet to change it as you see fit.

If you just wanted to see the examples for a CmdLet:
Get-Help Set-VMNetworkAdapterVlan -Examples

Open in new window

If you're not sure what you're looking for your best bet is one of the two below:
Get-Help Set-VMNetworkAdapterVlan -Full
Get-Help Set-VMNetworkAdapterVlan -Full | more

Open in new window

Help is normally also published on TechNet (almost always for MS CmdLets):

http://technet.microsoft.com/en-us/library/hh848475.aspx

However, it should be noted that you must mind the Version (directly beneath the CmdLet name) because things always change and not all options are available to all versions of any given Cmdlet.

If you're not sure what command you need, you may be able to work with the generally well structured naming in PowerShell. For example, you might look at the lists returned by:
Get-Help *vlan*
Get-Command *vlan*

Open in new window

Or you may just look at everything a particular module offers:
Get-Command -Module Hyper-V

Open in new window

Not sure what modules you have? You can use this to see:
Get-Module -ListAvailable

Open in new window

In many cases, parameters which expect certain types of input will let you tab through all of the possibilities. For example:
Get-Help -Name <Tab,Tab,Tab,Tab>

Open in new window

While that one isn't the most practical example the same applies to many CmdLets. You can tab through the parameter names in a similar manner.

It goes on and on really. PowerShell is a bit of an explorers language if you start to dig into it (and have the interest to do so). If you don't want to dig in, a small number of "template" scripts can take you a long way. For example, this loop type is repeated again and again:
Get-Something | Where-Object { $_.Property -eq "SomeValue" } | ForEach-Object {
  Do-Something $_.Identity
}

Open in new window

Finally, you may find these useful:

http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-components-postattachments/00-01-52-56-34/Cheat-Sheet-V1.00.pdf
http://www.microsoft.com/en-gb/download/details.aspx?id=42554

Chris
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 40424875
If you need to capture information about what the current settings are before changing them, there's often a "Get-" command that matches up with a "Set-".  So you could use something like Get-VMNetworkAdapterVlan to see what the settings are before you change them with Set-VMNetworkAdapterVlan.

In all the stuff I do with PowerShell, I rarely if ever encounter something that has a default (certainly nothing's coming to mind right now).
0
 
LVL 1

Author Closing Comment

by:Vas
ID: 40426768
Thank you both!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

624 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