Calling a Function Within a For-Each in Powershell

Error:
Unexpected token 'in' in expression or statement.
At :line:1 char:22
+ ForEach-Object ($i in  <<<< $fs_size_info) { $i.Name.Name, GetGB($i.Sum)  }
Code:
foreach ($i in $fs_size_info) { $i.Name.Name GetGB($i.Sum) }
If I omit the function from inside this foreach, it works perfectly, and I can access $i.Sum within the foreach as well. The problem arises when I try to call a function from inside the foreach. GetGB simply returns a more readable format e.g. GetGB(1024)
will return "1 K" etc...
I don't understand what I'm doing wrong, unless you cannot call a function inside a foreach statement.... am I missing something?
Thanks

The code you've posted and the error message don't seem to go together, unless the line before that "foreach" keyword happens to have ended with a pipe character.  There's a difference between how you use the foreach statement (help about_Foreach)
and the ForEach-Object cmdlet (help ForEach-Object).
Either way, it looks like inside the loop body, you've got two statements:  ($i.Name.Name) and (GetGB($i.Sum).  Those statements need either a line break or a semicolon between them.

Similar Messages

  • Can we call a function within a function??????Urgent

    Dear All,
    Like we can call a procedure from another procedure , in the same way can we call a function within a function. Please reply it's urgent.
    Regards

    > Please reply it's urgent.
    My usual soapbox response.
    Saying your posting is urgent is rude and arrogant. Why? Because you are saying that other people who have posted problems here, have less important problems than yours. That despite how complex and critical their problem may be, yours take priority.
    You're also demaning attention and a quick answer from people that provide support here - in their free time... and not getting paid a single cent for their efforts.
    So just how can you demand any urgency to your posting from them?
    Remember that this is a public forum. You cannot demand anything here. This is not Oracle Support. There are no SLA's here. Basic nettiquette applies.

  • Need Help: Using Ref Cursor in ProC to call a function within a Package

    I'm calling a function within a package that is returning a REF CURSOR.
    As per the Oracle Pro*C Programmer's Guide, I did the following:
    1) declared my cursor with a: EXEC SQL BEGIN DECLARE SECTION and declared the cursor as: SQL_CURSOR my_cursor;
    2) I allocated the cursor as: EXEC SQL ALLOCATE :my_cursor;
    3) Via a EXEC SQL.....END-EXEC begin block
    I called the package function and assign the return value to my cursor
    e.g. my_cursor := package.function(:host1, :host2);
    Now, the only difference between my code and the example given in the Pro*C Programmer's Guide is that the example calls a PROCEDURE within a package that passes back the REF CURSOR as an OUT host variable.
    Whereas, since I am calling a function, the function ASSIGNS the return REF CURSOR in the return value.
    If I say my_cursor := package.function(:host1, :host2); I get a message stating, "PLS-00201: identifier MY_CURSOR" must be declared"
    If I say :my_cursor := package.function(:host1, :host2); I get a message stating, "ORA-01480: trailing null missing from STR bind value"
    I just want to call a package function and assign the return value to a REF CURSOR variable. There must be a way of doing this. I can do this easily in standard PL/SQL. How can this be done in Pro*C ???
    Thanks for any help.

    Folks, I figured it out. For those who may face this problem in the future you may want to take note for future reference.
    Oracle does not allow you to assign the return value of a REF CURSOR from a FUNCTION ( not Procedure - - there is a difference) directly to a host variable. This is the case even if that host variable is declared a CURSOR variable.
    The trick is as follows: Declare the REF CURSOR within the PL/SQL BEGIN Block, using the TYPE statement, that will contain the call to the package function. On the call, you then assign the return REF CURSOR value that the function is returning to your REF CURSOR variable declared in the DECLARE section of the EXEC SQL .... END-EXEC PL/SQL Block.
    THEN, assign the REF CURSOR variable that was populated from the function call to your HOST cursor varaible. Then fetch this HOST Cursor variable into your Host record structure variable. Then you can deference individual fields as need be within your C or C++ code.
    I hope this will help someone facing a deadline crunch. Happy computing !

  • If statement within a for-each

    I'm trying to display the contents of the field DESCRIPTION if the field CUSTOMER_TRX_TYPE='Projects Invoice'. The output is within <?for-each:G_LINE?>, but CUSTOMER_TRX_TYPE is two levels above G_LINE - can I still reference the field?
    The xml hierarchy looks like:
    LIST_G_TRX / G_TRX / LIST_G_LINE / G_LINE
    I tried
    <?for-each:G_LINE?> <?if:[../CUST_TRX_TYPE='Projects Invoice']?> DESCRIPTION <?end if?>
    but that generated an error. Does anyone know if this is possible? If so, where my errors are?
    Thanks,
    Ed

    I found the answer to my own question ... for anyone else who might be hitting this problem, I needed one more ../ to get me to the level I needed. The following worked:
    <?for-each:G_LINE?> <?if:[../../CUST_TRX_TYPE='Projects Invoice']?> DESCRIPTION <?end if?>

  • XSLT for-each within another for-each

    Hi All,
    My XSLT mapping needs to pick a field(BOL) from the Header and the using that, search the Items node for the matching BOL and generate the output accordingly.
    My current XSLT is as follows(not the entire program, just the snippet)
         <xsl:for-each select="ns0:Messages/ns0:Message1/ns1:MT_Header/Header">
                          <xsl:param name="search"><xsl:value-of select="bol"/></xsl:param>
         <xsl:for-each select="ns0:Messages/ns0:Message2/ns1:MT_Items/Item[BOL=$search]">
                  <Output>
                     <BOL_ITEM><xsl:value-of select="BOL_ITEM"/></BOL_ITEM>
                </Output>     
         </xsl:for-each>
         </xsl:for-each>
    The following code works correctly(without the outer for-each and with hardcoding)
                             <xsl:param name="search">100</xsl:param>
         <xsl:for-each select="ns0:Messages/ns0:Message2/ns1:MT_Items/Item[BOL=$search]">
                  <Output>
                     <BOL_ITEM><xsl:value-of select="BOL_ITEM"/></BOL_ITEM>
                </Output>     
         </xsl:for-each>
    So its the for-each within another for-each that does not work . Is there some syntax problem ? Or another way to achieve this in XSLT?

    Closing this thread

  • Unable to set a new value in an extended property from within a For Each Loop

    Setting a new value in an extented property fails when the property is dereferenced within a For Each loop usin the item  iterator. However, if you use the First or Last Iterators from the Find Targets activity works fine.
    The error message is : "Setting a value for this object type is not allowed"
    I believe this is a defect, can you please confirm

    Looks like a bug that needs to be reported.
    While we are figuring out the issue you can work around the bug.
    Add another "Find Targets" inside the loop, and use the ID of the current item in the loop to find the target (again) by ID.
    And then use Set Variable on the target that was just found...
    I know... Not an ideal workaround, so please open a Severity 4 bug for this.

  • Call a functions within a function ?

    Hi
    Is there anyway to call my functions within a function ?
    function musicPlayer() {
         trace("Music");
         function pauseMusic(){
              trace("Pause");
    if i call musicPlayer function i will get Music in output now how can i call pauseMusic from outside of parent function !?
    is this possible ?
    thanks in advance

    You can call functions within other functions, but you don't want define functions inside other functions... they will only have scope within the function if they work at all.
    function pauseMusic(){
         trace("Pause");
    function musicPlayer() {
         trace("Music");
         pauseMusic();
    musicPlayer();

  • How to Call C functions within Flash?

    I have a bunch of functions written in C++. I would like to
    be able to call these functions within my flash application so that
    I can pass data to the functions and get the returned values. Is
    this possible with Flash 8?
    If this is not possible then is there a way that I can have
    Flash share memory space with another stand-alone application? This
    way, a C++ program could read and write data to the shared memory
    and Flash could also read and write to it.

    you can write a dll and then call mmexecute in the flash IDE,
    but I
    think in the player it is not possible.
    mProjector on windows will let you write c plugins that you
    can call from Flash
    http://www.screentime.com/software/mprojector/plugins.html
    give it a look - it might do what you need...
    On 2006-05-04 15:50:24 -0400, "mmakrzem"
    <[email protected]> said:
    > I have a bunch of functions written in C++. I would like
    to be able to
    > call these functions within my flash application so that
    I can pass
    > data to the functions and get the returned values. Is
    this possible
    > with Flash 8?
    >
    > If this is not possible then is there a way that I can
    have Flash
    > share memory space with another stand-alone application?
    This way, a
    > C++ program could read and write data to the shared
    memory and Flash
    > could also read and write to it.
    John Pattenden
    Screentime Media
    Flash Screen Saver, Application and Wallpaper tools
    http://www.screentime.com

  • How do i call a function within the jsp?

    Hi,
    What i am doing is now allow a user to type in comment and when the user click on "Add" button, it will call my function and write to a txt file.How can i call a custom jsp function within my jsp page or what is the correct way to do this?
    [My current codes]
    <form name="SubmitEvent" method="post" action="addComment()">
    </form>
    function addComment()
    System.out.println("Entered Add Comment function");
    Thanks for your help!

    You can define a Java Bean (I presume you know the rules to write a Java Bean) and send the read value as parameter to the Bean and then call a function in the Bean from the JSP.
    Contact me if you need more help!

  • What are the advantages of utilizing a dynamic VI compared to utilizing the VI Call Configuration Dialog Box Reload for each call option?

    Is it more efficient to use a dynamic VI or utilize the VI Call Configuration Dialog Box which apparently can perform the same function? I realize that there are restrictions on using the VI Call Configuration Dialog Box, however, if my scenario doesn't concern the restrictions, why would I want to go thru the trouble of creating a dynamic VI when I could simply click on the VI of interest and configure from a menu? Are there performance advantages? Thanks in advance!

    Generally, I wouldn't recommend playing with the call setup dialog at all (for those who don't know it, you can get to it by right clicking a subVI in the BD). By default, VIs are configured to load with callers and that's the correct options for almost all static VIs. The Open VI Reference primitive has multiple advantages:
    It allows you to select different VIs dynamically.
    It allows you to spawn multiple copies of reentrant VIs.
    It allows you to perform asynch runs (although I think that this is something that should actually be available through the call setup dialog).
    It allows you to open references to VIs in other application instances.
    In the rare cases where you do want the same functionality that the call setup dialog gives you, it doesn't hide it.
    Try to take over the world!

  • How do you call a function within a package using OCI in C

    I am trying to call a user-defined function in Oracle 8.1.7 using OCI in C. I am getting a ORA-06550 PLS-00221, <function name> is not a procedure or is undefined. Can anyone tell me how I would call a function using OCI?
    Thanks.

    I think I figured it out, but I am now getting a ORA-06512 error; numeric or value error: character string buffer too small.

  • Start:Body within a For-Each

    I have a report where I have some fields at the top of the page that I want to repeat on every page, so I added a <?start:body?> under those fields so that it would repeat the information above. This report has been working great.
    The problem is that now I need to repeat the whole report for multiple employees. I added another for-each above the <?start:body?> and it is giving an error. Is there a way around this?
    For example, what I am trying to do is this:
    <?for-each:G_STUDENTS?>Employee Name
    HEADER INFO
    FIELD_X
    <?start:body?>
    <?for-each:G_CLASSES?>
    CLASS INFO
    <?end for-each?>
    <?end:body?>
    <?end for-each?>
    and repeat for multiple employees....
    thanks in advance!
    Rob
    Edited by: Rob M on May 17, 2011 3:54 PM

    i get the following (sorry for not formatting it correctly..not sure how to make it look nice):
    ConfFile: C:\Program Files (x86)\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\config\xdoconfig.xml
    Font Dir: C:\Program Files (x86)\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\fonts
    Run XDO Start
    Template: H:\Garland ISD\XML Publisher\PRD\GISD Learning Management Transcript\gisdolmtxmlr.rtf
    RTFProcessor setLocale: en-us
    FOProcessor setData: H:\Garland ISD\XML Publisher\PRD\GISD Learning Management Transcript\GISDOLMTXML loc data.xml
    FOProcessor setLocale: en-us
    oracle.apps.xdo.template.fo.area.NoAvailableAreaException: Not enough rendering area. Please look into the incomplete output file for cause.
         at oracle.apps.xdo.template.fo.elements.FormattingEngine.checkInfiniteLoop(Unknown Source)
         at oracle.apps.xdo.template.fo.elements.FormattingEngine.checkInfiniteLoop(Unknown Source)
         at oracle.apps.xdo.template.fo.elements.FormattingEngine.createNewPage(Unknown Source)
         at oracle.apps.xdo.template.fo.elements.FormattingEngine.startLayout(Unknown Source)
         at oracle.apps.xdo.template.fo.elements.FormattingEngine.run(Unknown Source)
         at oracle.apps.xdo.template.fo.FOHandler.endElement(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLTHandler$EEEntry.sendEvent(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLTMerger.startElement(Unknown Source)
         at oracle.xml.parser.v2.XMLContentHandler.startElement(XMLContentHandler.java:181)
         at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1288)
         at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:336)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:303)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:206)
         at oracle.apps.xdo.template.fo.FOProcessingEngine.process(Unknown Source)
         at oracle.apps.xdo.template.FOProcessor.generate(Unknown Source)
         at RTF2PDF.runRTFto(RTF2PDF.java:629)
         at RTF2PDF.runXDO(RTF2PDF.java:439)
         at RTF2PDF.main(RTF2PDF.java:289)
    thanks,
    Rob

  • Calling stored function within select

    Hi,
    I am working with ODP.NET and Oracle 8.1.7 for two years now and I solved a lot of problems. But now I am really in trouble:
    I need to call a stored function (that is within a package) from a select statement:
    Here is a very simple test case (the real select is much more complicated)
    select PFM.P_COSTING.CALC ( 0 ) from dual;
    this works fine in TOAD, but When I try to do the same from C#/ODP.NET, I always get the following error:
    ORA-00904: Invalid column name
    Can anybody help?
    Here my package (scheme is “PFM”):
    CREATE OR REPLACE PACKAGE BODY P_Costing AS
    FUNCTION Calc ( x number)
    return number IS
    BEGIN
    RETURN 1;
    END Calc;
    END P_Costing;
    thanks in advance
    markus

    It works fine for me, but you might not want to use "PFM.P_COSTING.CALC ( 0 )" as a column name.
    Try aliasing the expression
    select PFM.P_COSTING.CALC ( 0 ) result from dual;
    David

  • Problem with calling a function within a function

    My problem is with the getWidth and getLength functions. The problem I am having is with the fact that when I get an incorrect input I pass it through the function again, which give me a weird return. The return I get is the correct input plus all the previous incorrect inputs after that. The one that gets returned is first incorrect input? I don't know if you understand, but I would appreciate help for this beginner.
    **Sorry about posting in this forum... I just realized this is not for beginners. Help would still be appreciated.**
    import java.util.Scanner;
    //Calculates the area of a rectangle
    public class AreaRectangle {
        private static Scanner c = new Scanner(System.in);
        private static boolean isNumber(String in) {
            boolean isNum = false;
            int count = 0;
            for (int i=0;i<in.length();i++) {
                if (in.charAt(i) >= '0' && in.charAt(i) <= '9' || in.charAt(i) == '.') {
                    if (in.charAt(i) == '.') {count++;}
                    else if (count > 1){isNum=false;break;}
                    else {isNum = true;}
                else {
                    isNum=false;
                    break;
            return isNum;
        public static double getLength() {
            String input;
            boolean isNum;
            double length = 0;
            System.out.print("Please enter the rectangle's length: ");
            input = c.nextLine();
            isNum = isNumber(input);
            if (isNum) {
                length = Double.parseDouble(input);
            else {
                System.out.println("Incorrect input!");
                getLength();
            System.out.println(input);
            return length;
        public static double getWidth() {
            String input;
            boolean isNum;
            double width = 0;
            System.out.print("Please enter the rectangle's width: ");
            input = c.nextLine();
            isNum = isNumber(input);
            if (isNum) {
                width = Double.parseDouble(input);
            else {
                System.out.println("Incorrect input!");
                getWidth();
            System.out.println(input);
            return width;
        public static double getArea(double length, double width) {
            return width*length;
        public static void displayData(double length, double width, double area) {
            System.out.println("Width = "+width+" "+"Length = "+length+" "+"Area = "+area);
        public static void main(String[] args) {
            double l, w, a;
            l = getLength();
            w = getWidth();
            a = getArea(l, w);
            displayData(l, w, a);
    }Edited by: x713 on Apr 12, 2008 7:12 PM
    Edited by: x713 on Apr 12, 2008 7:19 PM

    You're calling things recursively and that's not good (at least not here).
    To clarify, please look:
        public static double getLength() {
            if (something) {
                do something else
            else {
                System.out.println("Incorrect input!");
                getLength();  // you call the entire method again here! This is the recursive call
        }Better is to have a while loop inside the method and repeat this loop until the input that the user enters is correct (or until they quits).

  • Calling javascript function within a uix event

    JDeveloper Version: 9.0.3
    Technology: UIX
    Goal: To gracefully log out of a database connection, invalidate session, and close browser.
    Currently I have a logout.uix page that contains a cancel and logout button. The cancel button redirects the user to the calling page. The logout button fires a logout event that in turn calls a servlet method that closes the user's database connection and invalidates the session.
    Question: Upon returning to the logout.uix page, how do I call the self.close() javascript function that will force the user to close the browser?
    Thanks in advance for any assistance you can provide.
    OraTeam

    yes, I think it can be achieved. Something like this should suffice
    <button text="Log Out" onClick="script that closes the window" >
                            <primaryClientAction>
                            <fireAction event="YourEvent goeshere" formSubmitted="true">
                              <parameters>
                                <parameter key="Session" value="closeSession"/>
                              </parameters>
                            </fireAction>
                          </primaryClientAction>
                        </button>in the event handler you should register the event that you would specify above.
    <handlers>
        <event name="YourEvent goeshere" >
          <method class="com.test.ConnectionInvalidate" method="closeConnection" />
        </event>
      </handlers>In your class the method would be like this
    public class ConnectionInvalidate {
    public static EventResult closeConnection( BajaContext context,
                                                    Page page,
                                                    PageEvent event )
                                                    throws Throwable
    //from the event get the parameters. (if required)
    // code here for the close of connection
    }When you click the button called "Log Out" the event is fired which closes the connection and javascript is also called which closes the window. Both will happen simultaneously.
    hope this helps.
    regards,
    raj

Maybe you are looking for

  • G/L Account - Vendor Creation

    Hi, Im trying to create Vendor master in MM, the reconsilation account field is a mandate. I have entered one of the G/L account created in OBD4 but Im getting the following error. Please let me know what should I do here. Entry ZHLL 0001111111  does

  • "could not complete your request because the disk is full"

    I have Photoshop Elements 3 on an older desktop I use for editing photos. Yesterday, I tried to pull up a photo from my connected camera to the PE3 window and got the following error mesaage instead: "could not complete your request because the disk

  • Why are some websites displayed with added question marks inside black diamonds

    Numbers are displayed with question marks inside black triangles before and following, possibly as column separators. == This happened == Every time Firefox opened == I attempted to access financial websites

  • App Store quit unexpectedly

    Hi Guys, my iMac 2011 having an issue on app store application anybody had the same problem? using Lion 10.7.4. TIA! Process:         App Store [376] Path:            /Applications/App Store.app/Contents/MacOS/App Store Identifier:      com.apple.app

  • Dreamweaver CC - In App Next to Email Address, Apply Updates?

    I'm working in Dreamweaver CC on Mac OS X Yosemite and when I go to Dreamweaver ->email address ->Apply Updates is there. Does this mean I need to apply the updates to the program? I thought that was accomplished when the "Cloud" icon on the desktop