Powershell, explained the difference betweem Get & Set

Hi,

Could you please clearly point out the difference between Get & Set in the powershell?
Example will be great

Thanks
LVL 1
defreyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

systechadminConsultantCommented:
Get Command is used to fetch some information via powershell. Set command is for change any thing.

For ex- related to Exhange.
Get-DistributionGroup will give me the details of Distribution group.
Set-DistributionGroup will allow me to change any parameters for Distribution group
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pjamCommented:
by using the commands:
help get-variables -examples, and help set-variables -examples, you yourself can see examples as below for the variables commandlet:
NAME
    Get-Variable

SYNOPSIS
    Gets the variables in the current console.

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>Get-Variable m*


    This command gets variables with names that begin with the letter "m". The command also gets the value of the
    variables.


    -------------------------- EXAMPLE 2 --------------------------

    PS C:\>Get-Variable m* -Valueonly


    This command gets only the values of the variables that have names that begin with "m".


    -------------------------- EXAMPLE 3 --------------------------

    PS C:\>Get-Variable -Include M*,P*


    This command gets information about the variables that begin with either the letter "M" or the letter "P".

    -------------------------- EXAMPLE 4 --------------------------

    PS C:\>Get-Variable -Scope 0
    PS C:\>Compare-Object (Get-Variable -Scope 0) (Get-Variable -Scope 1)


    The first command gets only the variables that are defined in the local scope. It is equivalent to "Get-Variable
    -Scope Local" and can be abbreviated as "gv -s 0".

    The second command uses the Compare-Object cmdlet to find the variables that are defined in the parent scope
    (Scope 1) but are visible only in the local scope (Scope 0).
NAME
    Set-Variable

SYNOPSIS
    Sets the value of a variable. Creates the variable if one with the requested name does not exist.

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>set-variable -name desc -value "A description"
    PS C:\>get-variable -name desc


    These commands set the value of the "desc" variable to "A description", and then get the value of the variable.



    -------------------------- EXAMPLE 2 --------------------------

    PS C:\>set-variable -name processes -value (Get-Process) -option constant -scope global -description "All
    processes" -passthru | format-list -property *


    This command creates a global, read-only variable that contains all processes on the system, and then it displays
    all properties of the variable.

    The command uses the Set-Variable cmdlet to create the variable. It uses the PassThru parameter to create an
    object representing the new variable, and it uses the pipeline operator (|) to pass the object to the Format-List
    cmdlet. It uses the Property parameter of Format-List with a value of all (*) to display all properties of the
    newly created variable.

    The value, "(Get-Process)", is enclosed in parentheses to ensure that it is executed before being stored in the
    variable. Otherwise, the variable contains the words "Get-Process".


    -------------------------- EXAMPLE 3 --------------------------

    PS C:\># set-variable -name counter -visibility private
    PS C:\>new-variable -name counter -visibility public -value 26
    PS C:\>$counter
    26
    PS C:\>get-variable c*
    Name Value
    ---- -----
    Culture en-US
    ConsoleFileName
ConfirmPreference High
CommandLineParameters {}
Counter 26
PS C:\>set-variable -name counter -visibility private
PS C:\>get-variable c*
Name Value
---- -----
Culture en-US
ConsoleFileName
ConfirmPreference High
CommandLineParameters {}
PS C:\>$counter
"Cannot access the variable '$counter' because it is a private variable"
PS C:\>.\use-counter.ps1
Commands completed successfully.


This command shows how to change the visibility of a variable to "Private". This variable can be read and changed
by scripts with the required permissions, but it is not visible to the user.

The sample output shows the difference in the behavior of public and private variables.
0
Dan McFaddenSystems EngineerCommented:
Its very simple...

A command that is prefixed with "GET-" will retrieve info about something.  Where a "SET-" command will change/update a configuration or condition of something.

For Example:

1. Get-Content - retrieves (gets) the content of the item that is referenced.
2. Set-content - writes to or appends (sets) the content of the item that is referenced.

The powershell command prefixes (verbs) are pretty straight forward and pretty much do what they state"

1. GET-SomeCommandName
2. SET-SomeCommandName
3. ADD-SomeCommandName
4. CLEAR-SomeCommandName
5. ENABLE/DISABLE
6. NEW
7. INVOKE
8. REMOVE
9. RENAME
10. RESET
11. SHOW
12. SPLIT
13. START/STOP
14. SUSPEND
15. TEST

Summary from Microsoft:  https://technet.microsoft.com/en-us/library/ms714428(v=vs.85).aspx

Dan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.