Solved

Powershell and configuring settings - how to remove a setting?

Posted on 2014-11-04
3
381 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
3 Comments
 
LVL 70

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 39

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

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

707 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

16 Experts available now in Live!

Get 1:1 Help Now