Writing User ObjectID to variable #Powershell2019 Community Moderator ElectionPowershell: null file always generated (output of Compare-Object)Setting Windows PowerShell path variableDetermine installed PowerShell versionHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?How do I concatenate strings and variables in PowerShell?Printing object properties in PowershellNode.js/Windows error: ENOENT, stat 'C:UsersRTAppDataRoamingnpm'Azure PowerShell Error - Output of Get-AzureRmLocation changes when stored to variablePowerShell Get-ADuser value as string

Can other pieces capture a threatening piece and prevent a checkmate?

Does .bashrc contain syntax errors?

Recruiter wants very extensive technical details about all of my previous work

Light propagating through a sound wave

My friend is being a hypocrite

Does the attack bonus from a Masterwork weapon stack with the attack bonus from Masterwork ammunition?

Worshiping one God at a time?

What favor did Moody owe Dumbledore?

Synchronized implementation of a bank account in Java

Is there a term for accumulated dirt on the outside of your hands and feet?

Probably overheated black color SMD pads

Do I need to consider instance restrictions when showing a language is in P?

Is this an example of a Neapolitan chord?

Generic TVP tradeoffs?

What can I do if I am asked to learn different programming languages very frequently?

Help rendering a complicated sum/product formula

How to define limit operations in general topological spaces? Are nets able to do this?

Unfrosted light bulb

Do US professors/group leaders only get a salary, but no group budget?

Asserting that Atheism and Theism are both faith based positions

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

How can my new character avoid being a role-playing handicap to the party?

Am I eligible for the Eurail Youth pass? I am 27.5 years old

Why is indicated airspeed rather than ground speed used during the takeoff roll?



Writing User ObjectID to variable #Powershell



2019 Community Moderator ElectionPowershell: null file always generated (output of Compare-Object)Setting Windows PowerShell path variableDetermine installed PowerShell versionHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?How do I concatenate strings and variables in PowerShell?Printing object properties in PowershellNode.js/Windows error: ENOENT, stat 'C:UsersRTAppDataRoamingnpm'Azure PowerShell Error - Output of Get-AzureRmLocation changes when stored to variablePowerShell Get-ADuser value as string










1















I am looking to find a way to write the Object ID of a user to a variable automatically via AzureAD.




Get-AzureAdUser -ObjectId "Contose@contoso.com"




will give the output of the ObjectId, DisplayName, UPN, UserType



I am looking to the write the ObjectId of the user (e.g qwert_1232_trwwqe) to variable such as $UserId for use further in the script.










share|improve this question




























    1















    I am looking to find a way to write the Object ID of a user to a variable automatically via AzureAD.




    Get-AzureAdUser -ObjectId "Contose@contoso.com"




    will give the output of the ObjectId, DisplayName, UPN, UserType



    I am looking to the write the ObjectId of the user (e.g qwert_1232_trwwqe) to variable such as $UserId for use further in the script.










    share|improve this question


























      1












      1








      1


      1






      I am looking to find a way to write the Object ID of a user to a variable automatically via AzureAD.




      Get-AzureAdUser -ObjectId "Contose@contoso.com"




      will give the output of the ObjectId, DisplayName, UPN, UserType



      I am looking to the write the ObjectId of the user (e.g qwert_1232_trwwqe) to variable such as $UserId for use further in the script.










      share|improve this question
















      I am looking to find a way to write the Object ID of a user to a variable automatically via AzureAD.




      Get-AzureAdUser -ObjectId "Contose@contoso.com"




      will give the output of the ObjectId, DisplayName, UPN, UserType



      I am looking to the write the ObjectId of the user (e.g qwert_1232_trwwqe) to variable such as $UserId for use further in the script.







      windows azure powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 22:23









      Brian Tompsett - 汤莱恩

      4,2421339102




      4,2421339102










      asked Mar 6 at 21:47









      LurkingMedal140LurkingMedal140

      84




      84






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Lee Dailey provides a good pointer:




          the usual way is to keep things in the $Var and simply address the properties when needed. So, assign the call to a $Var and get the value with $Var.ObjectID.




          That said, if you do want to store the object ID alone in a dedicated variable, simply access the .ObjectId property on the object returned by Get-AzureAdUser:



          $userId = (Get-AzureAdUser -ObjectId 'Contose@contoso.com').ObjectId



          In a follow-up comment you mention arriving at:



          $Var = Get-AzureAdUser -ObjectId "Contose@contoso.com" | Select ObjectId


          However, this use of the Select-Object cmdlet (whose built-in alias is select) is virtually pointless, as this still returns a (new, custom) object that requires you to access its .ObjectId property in order to retrieve the object ID value - and for that you could have just assigned the object returned by Get-AzureAdUser directly to $Var, as Lee suggests.



          It is possible to use Select-Object to extract a single property value, namely via the
          -ExpandProperty <propertyName> parameter
          :



          $Var = Get-AzureAdUser -ObjectId 'Contose@contoso.com' | Select -ExpandProperty ObjectId


          However, the (...).ObjectId syntax (dot notation) is not only more convenient, but also faster - and it even works on multiple objects (in PSv3+), in which case an array of values is returned (a feature called member enumeration).



          In short, Select-Object -ExpandProperty is only needed if you're processing very large collections that must be processed one by one in the pipeline.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032692%2fwriting-user-objectid-to-variable-powershell%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Lee Dailey provides a good pointer:




            the usual way is to keep things in the $Var and simply address the properties when needed. So, assign the call to a $Var and get the value with $Var.ObjectID.




            That said, if you do want to store the object ID alone in a dedicated variable, simply access the .ObjectId property on the object returned by Get-AzureAdUser:



            $userId = (Get-AzureAdUser -ObjectId 'Contose@contoso.com').ObjectId



            In a follow-up comment you mention arriving at:



            $Var = Get-AzureAdUser -ObjectId "Contose@contoso.com" | Select ObjectId


            However, this use of the Select-Object cmdlet (whose built-in alias is select) is virtually pointless, as this still returns a (new, custom) object that requires you to access its .ObjectId property in order to retrieve the object ID value - and for that you could have just assigned the object returned by Get-AzureAdUser directly to $Var, as Lee suggests.



            It is possible to use Select-Object to extract a single property value, namely via the
            -ExpandProperty <propertyName> parameter
            :



            $Var = Get-AzureAdUser -ObjectId 'Contose@contoso.com' | Select -ExpandProperty ObjectId


            However, the (...).ObjectId syntax (dot notation) is not only more convenient, but also faster - and it even works on multiple objects (in PSv3+), in which case an array of values is returned (a feature called member enumeration).



            In short, Select-Object -ExpandProperty is only needed if you're processing very large collections that must be processed one by one in the pipeline.






            share|improve this answer





























              0














              Lee Dailey provides a good pointer:




              the usual way is to keep things in the $Var and simply address the properties when needed. So, assign the call to a $Var and get the value with $Var.ObjectID.




              That said, if you do want to store the object ID alone in a dedicated variable, simply access the .ObjectId property on the object returned by Get-AzureAdUser:



              $userId = (Get-AzureAdUser -ObjectId 'Contose@contoso.com').ObjectId



              In a follow-up comment you mention arriving at:



              $Var = Get-AzureAdUser -ObjectId "Contose@contoso.com" | Select ObjectId


              However, this use of the Select-Object cmdlet (whose built-in alias is select) is virtually pointless, as this still returns a (new, custom) object that requires you to access its .ObjectId property in order to retrieve the object ID value - and for that you could have just assigned the object returned by Get-AzureAdUser directly to $Var, as Lee suggests.



              It is possible to use Select-Object to extract a single property value, namely via the
              -ExpandProperty <propertyName> parameter
              :



              $Var = Get-AzureAdUser -ObjectId 'Contose@contoso.com' | Select -ExpandProperty ObjectId


              However, the (...).ObjectId syntax (dot notation) is not only more convenient, but also faster - and it even works on multiple objects (in PSv3+), in which case an array of values is returned (a feature called member enumeration).



              In short, Select-Object -ExpandProperty is only needed if you're processing very large collections that must be processed one by one in the pipeline.






              share|improve this answer



























                0












                0








                0







                Lee Dailey provides a good pointer:




                the usual way is to keep things in the $Var and simply address the properties when needed. So, assign the call to a $Var and get the value with $Var.ObjectID.




                That said, if you do want to store the object ID alone in a dedicated variable, simply access the .ObjectId property on the object returned by Get-AzureAdUser:



                $userId = (Get-AzureAdUser -ObjectId 'Contose@contoso.com').ObjectId



                In a follow-up comment you mention arriving at:



                $Var = Get-AzureAdUser -ObjectId "Contose@contoso.com" | Select ObjectId


                However, this use of the Select-Object cmdlet (whose built-in alias is select) is virtually pointless, as this still returns a (new, custom) object that requires you to access its .ObjectId property in order to retrieve the object ID value - and for that you could have just assigned the object returned by Get-AzureAdUser directly to $Var, as Lee suggests.



                It is possible to use Select-Object to extract a single property value, namely via the
                -ExpandProperty <propertyName> parameter
                :



                $Var = Get-AzureAdUser -ObjectId 'Contose@contoso.com' | Select -ExpandProperty ObjectId


                However, the (...).ObjectId syntax (dot notation) is not only more convenient, but also faster - and it even works on multiple objects (in PSv3+), in which case an array of values is returned (a feature called member enumeration).



                In short, Select-Object -ExpandProperty is only needed if you're processing very large collections that must be processed one by one in the pipeline.






                share|improve this answer















                Lee Dailey provides a good pointer:




                the usual way is to keep things in the $Var and simply address the properties when needed. So, assign the call to a $Var and get the value with $Var.ObjectID.




                That said, if you do want to store the object ID alone in a dedicated variable, simply access the .ObjectId property on the object returned by Get-AzureAdUser:



                $userId = (Get-AzureAdUser -ObjectId 'Contose@contoso.com').ObjectId



                In a follow-up comment you mention arriving at:



                $Var = Get-AzureAdUser -ObjectId "Contose@contoso.com" | Select ObjectId


                However, this use of the Select-Object cmdlet (whose built-in alias is select) is virtually pointless, as this still returns a (new, custom) object that requires you to access its .ObjectId property in order to retrieve the object ID value - and for that you could have just assigned the object returned by Get-AzureAdUser directly to $Var, as Lee suggests.



                It is possible to use Select-Object to extract a single property value, namely via the
                -ExpandProperty <propertyName> parameter
                :



                $Var = Get-AzureAdUser -ObjectId 'Contose@contoso.com' | Select -ExpandProperty ObjectId


                However, the (...).ObjectId syntax (dot notation) is not only more convenient, but also faster - and it even works on multiple objects (in PSv3+), in which case an array of values is returned (a feature called member enumeration).



                In short, Select-Object -ExpandProperty is only needed if you're processing very large collections that must be processed one by one in the pipeline.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 19:59

























                answered Mar 6 at 22:52









                mklement0mklement0

                135k22252290




                135k22252290





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032692%2fwriting-user-objectid-to-variable-powershell%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович