Why -Command behaves differently for the same command ?

I have a script called a.ps1 containing
exit 38
We can run this script in the following three ways and we will get three
different results. Can somebody explain what is going on? Why this behaviour?
References to good sources of information would be greatly apreciated.
PS> powershell -File .\a.ps1; $LastExitCode
38
PS> powershell -command { .\a.ps1 }; $LastExitCode
1
PS> powershell -command "& { .\a.ps1 }"; $LastExitCode
0
quilx

Hi Quilx,
I'm so sorry for missing your points, However, these information may be helpful for you:
The folowing is an example:
param($code=99)
exit $code
Save this in a.ps1 script file. Launch a cmd.exe and run your script
Powershell.exe –noprofile –file “pathtoscript.ps1” 1234
Echo %ERRORLEVEL%
This returns 1234 (or whatever code you submitted to your script when you called it). The reason why so many people have trouble with returning exit codes is that they miss the –file parameter:
Without –file, powershell.exe returns either 0 or 1. That’s because now your code is interpreted as a command, and when the command returns an exit code other than 0, PowerShell assumes it failed. It then returns its own exit code, which is always 0 (command
ran fine) or 1 (command failed).
Reference from:
Returning Exit Codes from PowerShell
Returning Exit Code from Script
Best Regards,
Anna

Similar Messages

  • Why charged me twice for the same item? They have withdrew money from my bank account for the second time about half an hour later after the transaction was completed leaving me overdrawn.

    Why charged me twice for the same item? They have withdrew money from my bank account for the second time about half an hour later after the transaction was completed leaving me overdrawn.

    Hi Benjamins,
    I've checked your account—you have two ExportPDF subscriptions. One placed on October 20 2013, and the other placed on October 11 of this year. So, you were probably charged the auto renewal for the subscription placed in 2013, and then the new charge for this year's order.
    Please Contact Customer Care so that an agent can help get things situated for you. There's no reason to have two subscriptions to the same service, so an agent can help you cancel one, if you'd like.
    Best,
    Sara

  • Balance Display are different for the same GL account in FS10N & FAGLB03

    Hi,
    It was noted that the GL account Balance Display are different for the same GL account in FS10N & FAGLB03.
    Please advice what would have cause the matter.
    Thank you,
    Regards,

    Hi Vani,
    Think you are using version 6.0.
    I had observed that TCode FAGLB03, displayes balances for particular Ledger (0L) leading by default.
    While in FS10N there is no option for selecting ledger.
    Try FAGLB03 with all ledgers one by one.
    Add the total and then try to matc wiht FS10N.
    Assign points of Good.
    thanks

  • TS1424 Why was billed twice for the same app?

    Why did I get billed twice for the same game app?

    Contact iTunes support and ask (these are user-to-user forums) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Auth: Restrict Infoobject for Queries differently for the same user

    Hi guys,
    I need to restrict an infoobject differently for some queries (analysis authorization). For example, I need to give full hierarchie access for query 1 to user 1.  But for another query for the same user I need to restrict the hierarchie authorization. Furthermore, both queries are based on the same multi provider. It is not possible to use different multi provider ... the adjustment effort is to high (to many queries).
    I have set up an authorization with rsecadmin
    QUERY1:
    ZHier1     Hyrarchie 1
    ZHier2     Hyrarchie 2
    0TCAACTVT     Activity in Analysis Authorizations
    0TCAIPROV     Authorizations for InfoProvider
    0TCAVALID     Validity of an Authorization
    0TCTQUERY     Query
    -->I added the respective values for the queries, the used multiprovider, hierarchies, etc.
    I have set up the same for QUERY 2 with different Hierarchy and Query values, but it does not work correctly. The user is always authorized for the hierarchie values of both queries.
    Thanks foryour helpin advance!!
    Regards,
    Sven

    Hi Sankar,
    Sorry for the confusion. Lets focus only one hierarchy ... ZHier1. 
    QUERY1:
    ZHier1     -> value: node2
    0TCAACTVT     -> value: 2 & 3
    0TCAIPROV -> value: multiprovider1
    0TCAVALID     -> value: *
    0TCTQUERY     -> value: query1 (based on multiprovider1)
    QUERY2:
    ZHier1     -> value: node2.1 (sub node of node 2)
    0TCAACTVT     -> value: 2 & 3
    0TCAIPROV -> value: multiprovider1
    0TCAVALID     -> value: *
    0TCTQUERY     -> value: query2 (based on multiprovider1)
    But this does not work. When I use query2 in reports the user has access to node2 and not only to node2.1.
    Any idea?
    Thanks again!
    Sven

  • Distribution working differently for the same report

    Hello all,
    I created a template with 3 reports, each of which opens for 4 plants.
    Then, when I schedule the offline distribution process, 2 of the reports are generated correctly for all plants, while the 3rd has a strange behavior. This 3rd report has 2 sheets and opens correctly for 2 of the plants, while for the other 2:
    - in one sheet, the formulas are not converted to offline mode (like _epmOfflineCondition_ ) giving an "#Error, no current connection." message and the sheet is not protected; however, the report data is correct.
    - in the other sheet, everything works ok and  the sheet is protected;
    Any thoughts? Thanks,
    Ana-Maria

    Thanks Ashok,
    but unfortunately the above points are not applicable to the issue indicated:
    1. Log off&log on has no effect since this problem appears on all PCs and always for the same data group.
    2. The data group is available in the model cube and master data.
    3. We are using the ADMIN user to execute the process so we have all authorizations (also, these are defined at Country level and only one Plant from a Country is not working).
    4. The formula is correct.
    5. Since the report executes correctly as a standalone report and works for other plants, I don't believe there is an issue with it.
    The issue still persists.
    Ana-Maria

  • Sideways and Vertical displays different for the same song

    When I play music on my iPod touch 4th generation, the name of the song appears normally in the vertical position, but the first word is omitted in the sideways display. ("Awake And Alive" displays as "And Alive" when sideways.) How can I fix this?

    Hello Beverly,
    Thank you for the question.  I would be concerned too if I received two emails for the same purchase. 
    I suggest checking your purchase history in the iTunes Store to see if there are two separate charges listed for this song.  Use the steps in the following article to check your purchase history in the iTunes Store:
    iTunes Store: See your purchase history and web order numbers
    http://support.apple.com/kb/HT2727
    If you do in fact see two separate charges for the same song, you can report the issue to the iTunes Store using these steps:
    To report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase, follow these steps:
    Find the email receipt for your purchase.
    Click Report a Problem under the app that is having the issue.
    When prompted, enter the Apple ID and password you used to purchase the item, then click Report a Problem.
    Click Report a Problem next to the item you are having an issue with.
    From the Choose Problem dropdown menu, choose the appropriate issue.
    Follow the onscreen instructions and—if prompted—type a description of the problem into the text field.
    Click Submit to have your issue reviewed.
    Find the full article here:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
    http://support.apple.com/kb/ht1933
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Why's the SQL format different for the same report on different PCs?

    I have 2 PCs running the same version of Crystal Reports (11.0.0.1994) using an identically configured system DSN with the exact same driver. When I view the SQL that CR is using on PC 1, part of it looks like this:
    " FROM   {oj (("PUB"."LOQEstimate" "LOQEstimate1" LEFT OUTER JOIN "PUB"."LOQComponent" "LOQComponent1" ON ("LOQEstimate1"."Estimate-ID"="LOQComponent1"."Estimate-ID") AND"
    On PC 2 it looks like this:
    "FROM   "PUB"."LOQEstimate" "LOQEstimate1", "PUB"."LOQComponent" "LOQComponent1", "PUB"."CustContact" "CustContact1", "PUB"."LOQSegment" "LOQSegment1"
    WHERE"
    It's the exact same report. Can someone tell me why the SQL is different?
    TIA for the help.

    Thanks for the reply, Patrick. Here are the answers you requested:
    1. Verify you are indeed using the same driver, and they are of the same version
    The driver on both PCs is the Progress OpenEdge 10.1A driver. The file is pgoe1021.dll, version 05.10.0037.
    2. Verify if you have the same database client install on both computer.
    Both use prowin32.exe, v10.1.1.1326
    If everything is the same, then it might be a registry key, and in this case, can you provide the following information:
    1. What database are you connecting to? ( Oracle, DB2, ... )
    Progress OpenEdge 10 RDMS (/community [original link is broken])
    2. What is the version of the database?
    10.1A
    3. What is the version of the database client?
    v10.1.1.1326
    4. How are you connecting to your database? ( Native, ODBC, OLEDB,... )
    ODBC
    5. If you are connecting via ODBC, what is the name of the driver used and it's version?
    The driver is the Progress OpenEdge 10.1A driver. The file is pgoe1021.dll, version 05.10.0037.
    6. What is the SQL query syntax do you prefer? ( PC 1, or the one generated on PC 2 )
    The SQL generated on PC1 doesn't return any records. The SQL generated on PC2 does. Records are preferable ;o)

  • JTree look,why it si different in the same application

    Hi,
    I have app that consists of two panels ,in each panel i have placed jtree component(each jtree has its own model-source)
    First panel is OK:
    http://img135.imageshack.us/img135/5049/goodmx7.jpg
    Unfortunately, in the second panel when i cretae new jtree using absoltely the same method,its look is completely different:
    http://img135.imageshack.us/img135/4403/badrg8.png
    How to make the second jtree looks like the first one?

    cichy410 wrote:
    I have app that consists of two panels ,in each panel i have placed jtree component(each jtree has its own model-source)When you say "I have app" do you mean you wrote the app or got it from somewhere?
    If the former, post some code and ask a specific question about what you don't know or understand. Better still, post a SSCCE that clearly demonstrates your problem.
    If the latter, you might consider asking the source, since we know nothing about it. Of course, I'm assuming you have the right to use the code.
    db

  • Java-puzzlers...Why 2 different outputs for the same line

    Here, why it is giving 2 different outputs for the same set of lines
    Line-1 and Line-2 are both same.But giving 2 different results ???
    /*java-puzzlers*/
    public class Elementary {
        public static void main(String[] args) {
             System.out.println(12345 + 5432l);  /*Line-1: Original statement- didn't modify*/
          System.out.println(12345 + 54321);  /*Line-2: I wrote - I delete 12345 + 54321 and wrote the same thing again*/
    }

    kjshikal wrote:
    one of them is a longkjshikal,
    For the third and final time. Please stop resurrecting old threads like this.
    Thank you for your co-operation.

  • HT1390 Why do I get a different movie price for the same movie on my iPad and iPhone. And 1 device says I can rent it but the other doesn't ,.?

    Why do I get a different movie price for the same movie on my iPad and iPhone. And 1 device says I can rent it but the other doesn't ,.?

    Adding Open DNS codes to your Network Preferences, should give good results in terms of speed-up as well as added security, (including anti-phishing and redirects) (Full information about Open DNS is here: http://www.opendns.com/home/nobloat ) and further independent information can be read here:
    http://reviews.cnet.com/8301-13727_7-57338784-263/free-dnscrypt-tool-enhances-ma c-web-security/?tag=mncol;txt
    and here:
    http://www.macworld.com/article/1146064/troubleshootdns.html?t=234
    Open System Preferences/Network. Double click on your connection type, or select it in the drop-down menu, and in the box marked 'DNS Servers' add the following two numbers:
    208.67.222.222
    208.67.220.220
    (You can also enter them if you click on Advanced and then DNS)
    Sometimes reversing the order of the DNS numbers can be beneficial in cases where there is a long delay before web pages start to load, and then suddenly load at normal speed:
    http://support.apple.com/kb/TS2296

  • I have an iMac OS X Version 10.5.8 but I also have a MacBookPro 10.7.5 version, why software updates are not the same? For example, when I want to know how much memory can not store in the same way in either computer.

    I have an iMac OS X Version 10.5.8 but I also have a MacBookPro 10.7.5 version, why software updates are not the same? For example, the way to see how much memory I have in my iMac is diferent than MacBookPro. And where I can see the memory of the disc I've got in my iMac? Than you very much.

    If you want everything the same on both computers you need to be running the same OS X version. You can't because your iMac is a PPC machine, not Intel.
    But to see information about your hard drive is the same for both. Simply select the drive icon on the Desktop. Press COMMAND-I to open the Get Info window. Disk information is in the upper panel.

  • APs using different channels for the same SSID

    Hi,
    This might be a stupid question, but I am wondering why my Aironet 1602i and 2602i access points connected to the same controller would use different channels for the same network. Would this be to avoid interference? If so, I am planning to put 9 access points throughout the office and they will be fairly close to each other. Would this increase the risk of interference?
    Thanks,
    Tibet

    That is normal. The WLC is determining the best channel and being in different channels is the best. When you add more, the WLC will decide by the use if RRM what channels and power levels to allocate to each AP.
    Sent from Cisco Technical Support iPhone App

  • Different execution plans for the same sql

    Hi,
    Im testing our new 10gR2 database on Linux and I can't understand why the same query use different plan.
    Here are the details.
    Table name: invoice_detail
    Records: About 10,670,900
    Columns:
    No
    seq (the primary key is No+Seq). Each invoices contains +/- 10 invoice_details.
    category ( <- 10 different values )
    State ( <- 3 different values )
    Basically, I have an index on the primary key and another index on Category + State.
    My request:
    select *
    from invoice_detail
    where no=123456 <- Best index to use
    and state <> 'CANCEL'
    and category = 'INVOICE'
    If i run this query from Toad or sql+, that's fine.
    The same query (i'm watching it from EM) executed via Forms use the category+state index.
    When I first import the database, the last thing I do is to run DBMS_STATS.GATHER_DATABASE_STATS.
    At this point, Forms use the right index.
    The day after (after the database has been analyzed with the predefined job via EM) Forms use the wrong index.
    I re-analyzed everything with exec DBMS_STATS.GATHER_DATABASE_STATS but the problem is still there.
    Thanks in advance

    I'm already using bind variables.
    I changed the "Estimated Percentage" to 100% in "Gather Optimizer Statistics Default Options" and now it seems to use the correct index. I'm stressed because I dont understand why it chooses different plan for the same sql.
    Actually, my users test the migration 1 day after I load all the data (drop schema-create schema-load data-analyze database) and at this point everythings go fine. After the second analyze of the database, the DB choose the wrong indexes.
    I really cannot migrate until I understand why it happens.
    Any ideas?
    TIA

  • Two different accounts to be posted for the same valuation class on PGI

    Hi Experts,
    Please note that we want to post two different accounts for the stock offset entry( based on the nature of customer ) in the transaction of PGI in SO. However the valuation class is the same as the nature of the material is same (only the nature of customers is different). We have put one of the two accounts in OBYC GBB - VAX and GBB - VAY.
    Is it possible to have two offset accounts on PGI for the same valuation class.If yes, how will the system identify which one to be posted to.
    Thanks in advance for answers..
    KJU

    hi
    why not create two asset class to easily to separate two situations for two company codes? just a suggestion
    or
    maintain one depreciation key for asset class as a default, if for another company code, just change the depreciation key manual when creating asset master. it is not very complicate.
    or
    create two depreciation areas, one for each company code, then, you will have one useless depreciation for each company code -- not a resonable way
    and, yes, that is the limitation of substituion in AA.
    best regards, Lawrence

Maybe you are looking for

  • Problem in JDBC to JDBC scenario

    Hello all, I am working on a JDBC 2 JDBC Scenario. Everything gone fine, data is picked from source, but it is not updated in the destination. I could not see any message related to this in SXMB_MONI it shows only messages related to IDOC, on search

  • Only OpenDirectory admins can see freebusy

    I'm running OSX Server 10.5.6, and have an iCal instance running with users set up through Open Directory. However, only people set up as admins in Open Directory are able to see freebusy information in their clients. I'm guessing that freebusy acces

  • Budget set up navigations in 4.6C

    Hi I am using 4.6C version, Can I find following navigations for  budget in this verson? 1. Financials->Budget Setup->Budget 2. Administration -> System Initialization -> General Settings -> Budget tab. thanx sravanthi

  • Deploy Forms 9i applications on Websphere Application Server Ver 6.1.1

    Can we Deploy applications developed using Forms 9i in Websphere Application Server Ver 6.1.1? Thanks in advance.

  • When making adjustments with lens correction, the crop isnt contrained to the image

    When I first installed CC I was able to rotate, or adjust the image in lens correction and it would automatically crop to the available image dimensions. But I deselected the contrain to image section in crop mode, and since then it hasnt work, even