Append string to variable in each iteration of for loop in Powershell.

Thanks so much I was able to get it working with the following command!
PowershellGet-Mailbox | where {$_.Name -eq "admin"} | foreach-object {Set-Mailbox -Identity $_.Name -DisplayName "$($_.DisplayName) ABBREVIATION"}
As for their reasoning behind wanting multiple mailboxes, they seem to be wanting to operate as 2 separate entities still. So their old clients still work with them under the old company name and they are paranoid about having names crossover mistakenly. We did try to get them to switch over to 1 mailbox and demonstrated it for them, but this is what they requested.

I have to ask - why keep two separate mailboxes for each user rather than just have one mailbox with multiple addresses?But yes, you can concatenate just like other languages. You have two problems currently -
1. You aren't referencing anything with "$.DisplayName". You need to use "$_.DisplayName" and you need to use it in a Foreach-Object script block.2. You need to pass the concatenated string as a single argument to the -DisplayName parameter. There are several ways to do this but the problem you're having is because there is whitespace in your argument.
PowershellGet-Mailbox | where {$_.Name -eq "admin"} | foreach-object {Set-Mailbox -DisplayName ($_.DisplayName + ' ABBREVIATION')}#ORGet-Mailbox | where {$_.Name -eq "admin"} | foreach-object {Set-Mailbox -DisplayName "$($_.DisplayName)ABBREVIATION"}

Similar Messages

  • Displaying data in chart for each iteration of FOR loop

    Hi Flex experts,
    I'm coding an Actionscript routine that has a series of
    complex calculations within a for loop. I would like to display
    some of the calculation results in a Flex chart at the end of each
    iteration of the loop. Thus far, I can only get the chart to
    display the results from the last iteration, but not any of the
    preceding iterations.
    Any tips or pointers would be greatly appreciated.
    Thanks,
    Dean

    Please have look at callLater method. You can call your
    chart-updating method thru callLater and that might help.
    Otherwise, can you share some of your code in the loop?
    ATTA

  • Repeating nodes using FOR loop but when concating XML string then concating only last iteration of FOr loop ??

    I stuck with a problem that I am using FOR loop for generating repeating nodes. 
    Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
    can anybody suggest me a way to handle this error....
    FOR i IN 1..pl_phone_tab.Count
    LOOP
    SELECT xmlelement("Phone"     
                                        ,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
                         ,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
                         ,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
    INTO p_phone_xml
    FROM dual; END LOOP;
    SELECT xmlelement("PhoneInfo"
                           ,xmlconcat(p_phone_xml))
    INTO p_phone_info_xml
    FROM dual;
    here I am getting only one node but there has to be two nodes for PHONE node

    Not that I'm encouraging you but here are two standalone examples explaining how to do what you want :
    1) Loop through the input collection and append each node to its target container :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml       xmltype;
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    emp_info_xml := xmltype('<EmpInfo/>');
    18 
    19    -- looping through emp collection and appending to EmpInfo element
    20    for i in 1 .. emp_tab.count loop
    21      select appendchildxml(
    22               emp_info_xml
    23             , '/*'
    24             , xmlelement("Emp"
    25               , xmlattributes(emp_tab(i).empno as "id")
    26               , xmlforest(
    27                   emp_tab(i).ename as "Name"
    28                 , emp_tab(i).job as "Job"
    29                 )
    30               )
    31             )
    32      into emp_info_xml
    33      from dual;
    34    end loop;
    35 
    36    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    37 
    38  end;
    39  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml_tab   xmlsequencetype := xmlsequencetype();
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    -- looping through emp collection and appending to the collection of Emp nodes
    18    for i in 1 .. emp_tab.count loop
    19 
    20      emp_xml_tab.extend;
    21 
    22      select xmlelement("Emp"
    23             , xmlattributes(emp_tab(i).empno as "id")
    24             , xmlforest(
    25                 emp_tab(i).ename as "Name"
    26               , emp_tab(i).job as "Job"
    27               )
    28             )
    29      into emp_xml_tab(i)
    30      from dual;
    31 
    32    end loop;
    33 
    34    select xmlelement("EmpInfo", xmlagg(t.column_value))
    35    into emp_info_xml
    36    from table(emp_xml_tab) t ;
    37 
    38    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    39 
    40  end;
    41  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    Both solutions give the same output.
    Test them both and see which one fits better into your scenario.

  • Need new result file for each iteration of a loop

    I am using TestStand 2010 SP1.  I have a main sequence that essentially does the following:
    Initialize the test equipment and set up the test environment [Sequence Call]
    Start Loop
    Run Tests [Sequence Call]
    End Loop
    Because testing can continue for hours, the resultant report file is enormous and difficult to evaluate. I need to create a new result file for each loop iteration.  I know that starting a new execution of “Run Tests” will create a result file for each iteration of the loop, but the new execution will not have access to the handles to the test equipment that were made during initialization.  The testing is time critical, therefore initializing the test equipment and setting up the test environment must occur outside of the loop. 
    How can I programmatically create a new result file at the beginning of the loop and close the result file at the end of the loop?  I am open to any other suggestions.  Thank you in advance for your help!

    Hi,
    You could modify your process model by making a copy of Test UUTs entry point. Then make the loop that usually tests multiple UUTs into your loop. Take the loop and init out of your sequence. You can init in PreUUTLoop or the other pre loop sequence, and maybe store your references in runstate.root.Locals and pass them to MainSequence. Then you can use Report Options to set it for separate report files.
    cc

  • How create a variable that changes (by 0.05) on each iteration in a loop?

    We are trying to control  New Era Syringe pumps using Labview. We want that those pumps could dispense different volumes on wells. For example 0.05ml in well one (using actuators we can move the wells),  0.1ml in well 2, 0.15ml in well 3 and so on. We think that we may need a "For loop" in which the number of iteration is the number of wells, but we do not know how to create a variable, inside the loop that can increase .05 on each iteration, and then we can use that variable as a "volume input" in our program.

    Hi tbob,
    multiple add operations with floats may induce more errors than a multiply/divide due to floating point representations (especially on numbers that can't be represented exactly, like 0.05)... The next step in this routine might be a comparison of setpoint and measurement value
    Message Edited by GerdW on 05-10-2010 08:04 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Variable not defined after running for() loop.

    Hi,
    I have a little problem, I have created a for loop, which seems to work, except that a variable within the for() loop gets lost, because if I try to call the variable after the loop, it says it's not there. anyway, here is my code, followed by the error. Thanks!
    <%
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:testdb");
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String sql_count = "SELECT COUNT(*) FROM users";
    ResultSet cn = stmt.executeQuery(sql_count);
    cn.first();
    int row_count = cn.getInt(1);
    int num = (int)(Math.random() * (row_count));
    int inum;
    for (inum=0; inum<row_count; inum++)
    int jnum = inum + num;
    if (jnum >= row_count) { jnum = 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    ResultSet rs = stmt.executeQuery(sql);
    int ce = rs.getInt("cr_earned");
    int cu = rs.getInt("cr_used");
    if ((ce-cu) > 0) { inum = row_count + 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    ResultSet rs = stmt.executeQuery(sql);
    rs.first();
    String url = rs.getString("url");
    con.close();
    %>
    ***********************ERROR***********************
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:93: Undefined variable or class name: rs
    rs.first();
    ^
    An error occurred between lines: 17 and 43 in the jsp file: /gtt/surf.jsp
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:94: Undefined variable or class name: rs
    String url = rs.getString("url");
    ^

    now i've defined them all before the loop and I get this error. Error is following modified code below.
    <%
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:testdb");
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String sql_count = "SELECT COUNT(*) FROM users";
    ResultSet cn = stmt.executeQuery(sql_count);
    cn.first();
    int row_count = cn.getInt(1);
    int num = (int)(Math.random() * (row_count));
    int inum;
    int jnum;
    ResultSet rs;
    for (inum=0; inum<row_count; inum++)
    jnum = inum + num;
    if (jnum >= row_count) { jnum = 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    rs = stmt.executeQuery(sql);
    int ce = rs.getInt("cr_earned");
    int cu = rs.getInt("cr_used");
    if ((ce-cu) > 0) { inum = row_count + 1; }
    rs.first();
    String url = rs.getString("url");
    con.close();
    %>
    ***********ERROR***************
    An error occurred between lines: 17 and 45 in the jsp file: /gtt/surf.jsp
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:95: Variable rs may not have been initialized.
    rs.first();
    ^
    Thanks anyone.... ;-)

  • Passing a variable's associated number between "for" loops & functions?

    Hi,
    I seem to be having a problem understanding how variable information can be passed between functions and arrays.
    I have variable "grab" set up as a Number.
    var grab:Number;
    My intent (I'll do my best to explain) is to have a number "attached" to grab when it is first mentioned in this function, itemClick.
    These should be all the relevant arrays:
    clickItemArray = [scene_Camp.wood, scene_Ax.ax]
    itemUsableArray = [wood2, ax2]
    sceneGuyArray = [scene_Camp.guy_Camp, scene_Ax.guy_Ax]
    function itemClick(event:MouseEvent) {
                    for (grab = 0; grab<clickItemArray.length; grab++) {
                            if(clickItemArray[grab].hitTestPoint(mouseX, mouseY, true)) {
                                    addEventListener(Event.ENTER_FRAME, itemRemoval);
                                    sceneGuyArray[grab].gotoAndPlay("guy_Notice");
                                    trace("guy_Notice");
    I would like to have the number established with grab (it would either be a 0 or 1, as clickItemArray,  sceneGuyArray, and itemUsableArray) be able to be passed into the next relevant function, itemRemoval. I was hoping to use variables so I could use the same function for whatever item was clicked upon. For example, if the clickItemArray item was 1 (the ax), then sceneGuyArray[grab] would = 1, and the right frame would play. That number 1 would be transferred to function itemRemoval, where it would constantly be listening for sceneGuyArray[1] also (where "1" would have been established through the initial "grab" in the first function), and react accordingly.
    function itemRemoval(event:Event) {
                    for (var grab2:uint = grab; grab2<sceneGuyArray.length; grab2++) {
                        if (sceneGuyArray[grab2].currentLabel == "guy_NoticeDone") {
                            //removeEventListener(Event.ENTER_FRAME, itemRemoval);
                            trace("cheese");
    I can't get the trace working, though. I'm sure I'm doing something wrong with "for" loops or the if statement.
    Naturally, help would be appreciated.

    I do have an unrelated question, if you happen to see this...
    Is there a way to "nest" for loops? (maybe there's a better term)
    For example, this is part of a function I have
    } else if (canClickBoo == false) {
                            //for the click array
                            for (var u:uint=0; u<clickToXArray.length; u++) {
                                //disable the mouse
                                clickToXArray[u].mouseEnabled = false;
                                clickToXArray[u].buttonMode = false;
                            for (var l:uint=0; l<clickFromXArray.length; l++) {
                                clickFromXArray[l].mouseEnabled = false;
                                clickFromXArray[l].buttonMode = false;
                            for (var o:uint=0; o<clickItemArray.length; o++) {
                                //enable items to be clicked
                                clickItemArray[o].mouseEnabled = false;
                                clickItemArray[o].buttonMode = false;
    Obviously each "for" loop does the same thing, set the items of each array "false" (make them unclickable if "canClickBoo" is false). In case each array has a different length, though, I can't just use a single "for" loop (afaik).
    I'm wondering if, based on what you see (naturally I can post more), I can simplify the code.

  • How to use no of iteration of for loop as the input for the for loop

    hi all,
    i wanna need some help here..
    i'm using for loop to iterate to ceratin no of iteration.. then, i would like to use back the no of iteration as the input of 'N' for the next iteration..
    in other word, eg:
    1st run:
    i insert a control to 'N', let say 80
    then the iteration run until 80-1 = 79..
    2nd run:
    i need to insert the no of "N", let say a control of 120.. i want the loop run for "120 - 79", where the 79 is the no of previous run..
     easy to say,
    how can i connect the "i' as a control to ''N''
    n how to make a "run' or ' GO' and ''stop'' button in the front panel and block diagram after the first run without using the stop and run from the labview window
    thanks..

    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
    Attachments:
    Untitled 2.vi ‏9 KB

  • Initializing more than one variable of different types in for-loop

    I know it is possible to initialize two variables of the same type in a for-loop like this:
    for(int i=0, j=0;i<=word.length/2;i++){}
    However, I'm trying to initialize two variables of different type in the initialization of for-loop. And the IDE won't let me do it..
    for(int i=0, double j=0;i<=word.length/2;i++){}
    Is it even possible to do initialize two variables of different type?

    Well, just for fun, you can write very generalized for loop. you can do it in a complicated way though.
    But, for god sake, why would you do that?
                 boolean someboolean = true;
              for(Object i=new Integer(0),j=new Double(1);someboolean;i=(Integer)i+1){
                   j =(Double)j + 1;
                   if((Double)j>3)
                        someboolean = false;
                   System.out.println("i: "+i+" j: "+j+" someboolean:"+someboolean);
              }

  • If a variable is declared in d for loop, can it be used afterloop exits?

    pls someone explain this to me!

    Do you remember The Green Phantom?i know a girl who has one..
    its long, vibrates at 4 speeds?Well, I suppose your breath is fresher when she uses it versus when ...
    No, I can't post that. [CANCEL]

  • 1D Array Of String To For-Loop

    Hi fellow engineers,
    I'm new to LabVIEW.
    I got a question,
    If I got a 1D array of string and I want to loop my program to the same number of times (Iteration) in conjunction with the numbers of sub-folders generated by the "list folder" function. How can I do it?
    Any help is greatly appreciated.
    Solved!
    Go to Solution.
    Attachments:
    Capture.PNG ‏7 KB

    Wire the string array to the border of the for loop. LabVIEW will automatically iterate through each element of the array; you should not wire anything to the N terminal of the for loop. This is the default behavior for arrays entering a loop; if you do not want auto-indexing, right-click on the tunnel (where the array enters the loop) to change the behavior.

  • So close but need help comparing strings in different subforms with for loop - Livecycle ES

    For some reason I was not able to post this in the Livecycle ES forum, even though I've posted there often in the past.
    I have created a form that I almost have working and I'm hoping someone can help me.
    We have eight billing teams in our company and each team works anywhere from 1 - 4 different clients. The form is used to track, per Billing Rep, the number of items of mail that each billing r5ep works each day. What I'm needing to add at the bottom is a subform that tracks the totals by client. So I'm trying to get the form to loop through all of the existing subforms (and the subforms within them) and compare a cell int he bottom subform to a cell in the other subforms, which are dynamically added, and then total ONLY those items. My script however is not working.
    What I have now is:
    var repCount = form1.P1._rep.count
    var itemCount = form1.P1.rep._ItemSet.count
    for (x=0; x<repCount; x++)
         for (i=0; i<itemCount; i++)
              if(clientName.rawValue == P1.rep[x].ItemSet[i].client.rawValue)
              this.rawValue = this.rawValue + P1.rep[x].ItemSet[i].corresp.rawValue;
    It seems like this should work but I'm getting the following error:
    P1.rep[x] is undefined
    So what it looks like is I'm missing is the proper way to reference the objects in these subforms.
    The form is here: https://acrobat.com/#d=20gWXZ4sBm4OPV6oO76zSg
    If someone could take a look at it I would be so grateful.
    Thanks,
    Jo

    I don't know that anyone else will ever have a similar problem as what I was having, but I figured I would go ahead and post the solution, just in case....
    The error I was getting (P1.resolveNode("rep[" + j + "].ItemSet[" + i + "]") is null) was occuring because the variable itemCount needed to be referenced within the repCount For Loop. I also needed to resolve the node for the itemCount, which I wasn't doing.
    So...my old code was this:
    var repCount = P1._rep.count;
    var itemCount = P1.rep._ItemSet.count;   //this part was throwing the error. Needed to use resolveNode...and needed to not declare the variable until inside the first For Loop.
    var nTotal = 0;
    for (var j=0; j<repCount; j++) {
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                nTotal = nTotal + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    this.rawValue = nTotal;
    ...which wasn't working because it was trying to reference the count of the ItemSet right up front...but it needed to wait until it got inside the first iteration of the repCount subfields...AND it needed to have resolveNode used.
    The corrected code is:
    var repCount = P1._rep.count;
    this.rawValue = 0;
    for (var j=0; j<repCount; j++) {
        var itemCount = P1.resolveNode("rep["+j+"]")._ItemSet.count;  //corrected code...node is resolved and variable is declared within the first subform repCount.
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                this.rawValue = this.rawValue + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    ...which now works perfectly...and I'm throwing a party to celebrate! LOL
    Jo

  • Reasons why to use Iterator for List rather than for loop ?

    when i use the iterator and for loop for traversing through the list. it takes the same time for iterator and also for for loop. even if there is a change it is a minor millisecond difference.
    what is the actual difference and what is happening behind the traversing list through iterator
    if we are using we are importing extra classes ...if we are using for loop there is no need to import any classes

    If you have an array-backed collection, like an ArrayList, then the difference between using an iterator and get() will be negligible.
    However, if you have a linked list, using get() is O(n^2) whereas iterator is O(n).
    So with an iterator, regardless of what your underlying data structure, a list of 100,000 elements takes 1,000 times as long to iterate over as a list with 100 elements. But using get() on a LinkedList, that same 100,000 element list will take 1,000,000 times as long as the 100 item list.
    There's no real benefit to ever using get()
    Side note: I've been comparing iterators to get(), not iterators to for loops. This is because whether it's a for or a while has nothing to do with whether you use an iterator or get(). The way I use iterators is for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Foo foo = (Foo)iter.next();
    }

  • Creating variables using for loop

    is there any way in java to create a variable called "xi" using a for loop say:
    for (int i =0; i < 1000000;i++){
      int xi;
    }so I want to create a million of different variable names based on the i... I know this may be a stupid question

    I don't think there is a way to do this. More importantly why do you want to do this? If you dynamically generate 1 million variables, then how will the rest of your program refer to them? Maybe what you need is some sort of collection.

  • For-loop & iterator.remove()

    Is it possible to remove an item during iterating with for-loop?
    for (SelectionKey opKey : selector.selectedKeys())
         // I need to remove opKey from selectedKeys set.
    }Is it really necessary to remove handled key from selectedKeys set? What will happen if I run selector.select() while selectedKeys set contains some keys?

    Desiderata wrote:
    Is it possible to remove an item during iterating with enhanced-for-loop?No
    Is it really necessary to remove handled key from selectedKeys set? What will happen if I run selector.select() while selectedKeys set contains some keys?[Selector Selection|http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/Selector.html#selop]

Maybe you are looking for

  • Version of developer 6i  in 11.5.10.2

    hi....! How to know the version of developer 6i in 11.5.10.2? regards vijay

  • Adobe 9: Can a PDF be modified that has been digitally signed?

    Is it possible to insert or remove pages from a PDF (in Adobe 9) after another user has already placed a digital signature in it? (This isn't a certified digital signature.) It appears that Adobe 9 does not allow a user to make modifications to a pdf

  • REFERENCING NEW

    Hi, on 10.2.0.3 on Win 2003, we have this trigger and insert on the table takes too much time : CREATE OR REPLACE TRIGGER USER.TRIGGER BEFORE INSERT ON MYTABLE REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLAREIs there any problem with trigger ?

  • How to use smileys in message in N79, please help

    i had other nokia models wher in i used to send smileys in messages, but now i have taken N79 and there is no smileys insertion possible in it. please tell me how can i do so. if any software download is required then also please tell me

  • Quick Profile Name system not working as expected

    When I open the EMET and I change the value of "Quick Profile Name" from Recommended Security settings to maximum security settings and then restart the application it always changes to "Custom Security Settings" and it also changes the Data Executio