Script with two conditions

hi friends
 I am new to PowerShell and i am studying hard since I've found it excellent to automate administrative tasks in my network.
I am trying to write an script whichchecks if ADDS service (which its service name is NTDS) exist & also if it is running, then my command which creates a set of objects in AD be executed (new-ADobject
I am familiar with get-service Cmdlet & also with basic "if statement", which is
if (my condition) {
do stuff
 but I don't know how to combine these things to make the final code.
may someone please write me the code, so that a begin to study about the different parts of the final code?
thanks a lot

I would start by studying hte very basic compnents of PowerShell.
You can write an if statement after only a few minutes of studying.  Itis easy.  Try it:
Start here:
http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx
For the absolute beginner:
http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
¯\_(ツ)_/¯
hello thanks. I studied and I learned how to use multiple conditions in my code,
but still have problem with writing the condition itself in this certain circumstance.
so am I on the right way by this:
$myservice = get-service -name NTDS | select status
if ($myservice -eq "running") {
New-ADObject.......

Similar Messages

  • Formated Search: Auto refresh with two conditions.

    Hi,
    I've created a Formated Search in one of my column.
    I defined my formated search as :
    - Auto refresh "When Exiting Altered Column" Item No.
    - Display Saved Values.
    Now how can I make it Auto refresh with two conditions?
    - Auto refresh "When Exiting Altered Column" Item No.
    And
    - Auto refresh "When Field Changes" Customers/Vendor Code.
    - Display Saved Values.
    Is there any way to make it work?
    Thanks In Advance.
    Bruce.

    Hi Bruce,
    You could try this trick.
    You need to execute SELECT1 in Col1 when Item No. column is altered or the Customer code is changed.
    Then, in the Item No. column asign a new Formatted Search which selects the Item No. column value (Its value) when the Customer code is changed.
    And in the Col1 asign a formatted search that acts when the Item No. column is altered.
    I think this should do the trick.
    Let us know if works.
    Regards,
    Ibai Peñ

  • Calculation of tax with two conditions

    hi all,
    i have an issue regarding tax in condition in po.
    i want the calculation of tax should be on two condition basis, while i am giving value in tax code field in invoice tab.
    1. when i am entering tax code, the value like- L1- 4%, L2- 12%, that is calculating on gross price.
    supose- GP- 100
         tax- 4%-     4
                        104
    then am puting fright charge- 10
    so total is 114
    2. supose- GP- 100
             fright     -  10
                            110
    then a will calculate- 4% on 110
    how this could be done, the 2nd one.
    thanks&regards
    susanta

    Hi,
    For this you have to treat Freight as a Discount Condition Type in MM Pricing
    Take a copy of RA01 in M/06 and keep it as Positive Condition
    Here keep
    Cond. class   A Discount or surcharge
    Calculat.type A Percentage
    Cond.category Blank
    And Plus/minus - A (Positive)
    Use this in Pricing Procedure (M/08) after Gross Price ad Discount conditions (before Subtotal)
    Now
    Base Price = 100
    Freight = 10
    Subtotal = 110
    Tax (4%) = on Subtotal

  • Print When with two conditions

    I only want to print a page if two conditions are met. On each section I am using the following Print When Condition:
    DateFormat(query.asofdate, "mm/dd/yyyy") NEQ DateFormat(calc.AmtDate, "mm/dd/yyyy")  AND LSNumberFormat((query.bal + calc.anticipated), "_.__") LTE LSNumberFormat(25.00, "_.__").
    The date check works great by itself and the amount check works great by itself but I can't get them to work together. Any ideas?
    I am using CF10.

    Cozmo2 wrote:
    That fixed the problem Thanks!
    Is there anyway I can apply this to the whole page and not have to add it to every sections 'Print When Condition'?
    One way would be to exclude records that meet those conditions. That way you would not need to take them into account in your report.

  • Calculation script with multiple conditions

    Hi. I am recreating an order form in Livecycle. I'd like to auto-populate some of the pricing info on the bottom based on data input on the top half of the form.
    I've tried several different sets of code, and come up with nothing that works.
    Here's an example scenario:
    If the checkbox for "offshore" and "bolting" is checked, the numeric field associated with bolting should be $50 * whatever number is in the bolting quantity box.
    So i need the script to check the offshore checkbox, and the bolting checkbox, assign a value to the numeric field and multiply it by another numeric field.
    There is the added complication of some customers having custom pricing, so I'd need to also figure out a code that is based on the customer selection.
    I also thought about, perhaps, putting the price info in drop down lists and enabling/disabling them based on the checkboxes up top.
    Ideally, though, the first scenario would be my preference.
    I tried this code (and many other variations of it) in both javascript and formcalc...in formcalc i get an error about the &.
    if (offshore == 1) && (bolting == 1) then
    $.rawValue == $50.00
    elseif
    (inland == 1) && (bolting == 1) then
    $.rawValue == $50.00
    elseif
    (land == 1) && (bolting == 1) then
    $.rawValue == $55.00
    elseif
    (rig == 1) && (bolting == 1) then
    $.rawValue == $50.00
    elseif
    (plant == 1) && (bolting == 1) then
    $.rawValue == $50.00
    elseif
    (yard == 1) && (bolting == 1) then
    $.rawValue == $55.00
    else
    $.rawValue = 0
    endif
    any help would be appreciated!

    You need more parenthesis.      
    if ((offshore==1) && (bolting==1)){
    //do stuff

  • Filtering a range with two conditions and totalling the filtered set

    I have got to :
    =SUMIF(LOOKUP(1, 1::K2:K79,  1::L2:L79), "=✓", 1::I2:I79)
    The error message is "SUMIF requires that all range arguments are the same size".
    My understanding is that :
    LOOKUP(1, 1::K2:k79, 1::L2:l79) will return a set of values filtered from L2:L79 in table 1 that correspond with all rows in K2:K79 (in the same table) that contain the numerical value 1.
    That set of values is then used as the first argument in a SUMIF statement to be filtered on "=✓" producing a subset whose corresponding rows in I2:I79 will be totalled.
    I've given it a good bit of effort now for a couple of hours and hope that someone can help me out of my amateur quandary with a formula that will achieve the same thing, because I am giving up : ie :
    Product
    Month
    Eligible product (✓) or not (x)
    Cost
    Teddy Bear
    1
    x
    £35.00
    High-resolution PC Monitor
    1

    £600.00
    Electric Fan
    1

    £45.00
    Newspaper subscriptions
    1
    x
    £45.00
    Snack foods
    1
    x
    £15.00
    Telephone line installation
    1

    £80.00
    Office chair
    2

    £75.00
    I need to efficiently calculate the total cost of "Eligible products" bought in Month 1.

    Hi b,
    LOOKUP returns a single value corresponding to the first match it finds for the search value.
    As I understand it, you wnt the SUM of all 'cost' values where the month is "1" AND 'eligible' is checked.
    For a SUM depending on more than one condition being TRUE, the function of choice is SUMIFS.
    If Row 1 is a Header row, and Row 179 is the last row in your table (or if no rows below that will match both conditions), you can omit the row part of each range address.
    I'm confused as to which column contains the amounts to be summed, so I've made these assumptions:
    K = month
    L = eligible
    M = cost
    O2: =SUMIFS(M,K,"=1",L,"=√")
    (The formula may go in any cell not referenced by the formula. My choice to place it in O2 was arbitrary.)
    Regards,
    Barry
    PS: Apple has provided an excellent guide to writing formulas in Numbers. The iWork Formulas and Functions User Guide is available for download via the Help menu in Numbers. It provides a description of each function with at least one example of how it may be used.
    B

  • Reminder with two conditions

    I need a script that iCal can trigger which will show a message ("Pay credit cards") if a) the date of the month is later than the 15th and b) if I haven't yet indicated that I've paid. I can do this in Filemaker, and I've created an applescript that will show the message based on the date, but I can't figure out how to create an applescript with an "I paid" answer field—one that will will stay "paid", once I select it, until the 15th of the next month. I'm obviously an inexperienced applescripter and help would be much appreciated.

    This is a rather unique situation that may require more understanding of your setup than is available… as such you might not get a direct answer.
    It seems to me that there are a couple of ways you can do here, depending on where you want to put the logic.
    You mention Filemaker, but I'm not sure whether you mean you're already using Filemaker and you want your script to integrate with it, or whether you mean you know how to do this in Filemaker, but not AppleScript?
    Storing the 'paid' status is relatively easy but it's not clear how you intend to indicate whether you've already paid or not (if this script pops up on the 15th, how is it supposed to know that you've already paid?
    So in short, you need to provide more details before anyone can really help you.

  • Batch job with 2 conditions

    Hi,
    We have a program that will create a batch job and then we need to go to SM35 to run that batch job manually. We want to avoid this manual step and what we want to do is to as soon as our program runs it will create a batch job and then batch job should kick off automatically.
    One of the solution that came to my mind is to schedule a batch job with two conditions:
    1. in first condition it will run our main program
    2. and in 2nd step it will look out for the batch job that created in SM35 and will kick off that, but I am not sure how can i do this using Sm36.
    I was also wondering if there is another way so that we can just avoid the batch run for the second step?
    So can you please help me with this.
    Thanks,
    Rajeev

    SM35 -> batch sessions, so I assume you are talking about these.
    You can start sessions under program control by submitting program RSBDCSUB after creation of the session.
    Thomas

  • How to set two Conditions Simultaneously in set where clause

    Hi,
    I have a messgechoice item , and i need to fire messagechoice VO with two conditions.
    For Eg:-- we have three Items ProjectContractor& Work Order on a custom Page , now i need work order list should populate on lelection of project & contractor both, so i have apply a fire partial event on contractor where i i get the parameter values as follows:--
    CO Code
    if("OrderNoself".equals(event))
    String value21 = (String)pageContext.getParameter("ProjectName");
    System.out.println("The Selected Project Name for self Contractor is "+value21);
    String value22 = (String)pageContext.getParameter("ContractorName");
    System.out.println("The SelectedContractor Name for ContractorName is "+value22);
    Serializable [] params11 = {value21,value22} ;
    am.invokeMethod("initWorkOrderNumberself",params11);
    AM Code
    public void initWorkOrderNumberself(String ProjectName,String ContractorName");
    getDprWorkOrderpopVO1().setWhereClause("PROJECT_NAME = " + "'"+ProjectName+"'");
    getDprWorkOrderpopVO1().setWhereClause("CONTRACTOR_NAME = " + "'"+ContractorName+"'");
    getDprWorkOrderpopVO1().executeQuery();
    Now when i run my form then Work order list only populateon set conditions ofContractor NAme only.
    Please suggest....

    Hi Tarun,
    Thanx for ur reply,
    i have used below mwntioned code provided by you but still i m getting error...
    public void initWorkOrderNumber(String ProjectName,String ContractorName)
    //getDprWorkOrderpopVO1().setWhereClause("CONTRACTOR_NAME = " + "'"+ContractorName+"'");
    //getDprWorkOrderpopVO1().executeQuery();
    getDprWorkOrderpopVO1().setWhereClause("PROJECT_NAME =:1 AND CONTRACTOR_NAME=:2");
    getDprWorkOrderpopVO1().setWhereClauseParams(null);
    getDprWorkOrderpopVO1().setWhereClauseParam(1,ProjectName);
    getDprWorkOrderpopVO1().setWhereClauseParam(2,ContractorName);
    getDprWorkOrderpopVO1().executeQuery();
    ERROR:---
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select * from omaxe_work_order_headers
    where work_order_number is not null) QRSLT WHERE (PROJECT_NAME =:1 AND CONTRACTOR_NAME=:2)
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:888)
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:862)
         at oracle.apps.fnd.framework.OAException.wrapperInvocationTargetException(OAException.java:985)
         at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:210)
         at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:152)
         at oracle.apps.fnd.framework.server.OAApplicationModuleImpl.invokeMethod(OAApplicationModuleImpl.java:721)
         at omaxe.oracle.apps.xxopa.boqmain.webui.OmaxeDPRCO.processFormRequest(OmaxeDPRCO.java:107)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:799)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
         at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1118)
         at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
         at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
         at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363)
         at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2633)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418)
         at OA.jspService(OA.jsp:40)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
         at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)
         at java.lang.Thread.run(Thread.java:534)
    ## Detail 0 ##
    java.sql.SQLException: ORA-01006: bind variable does not exist
    Regards
    Saurabh

  • Choosefrom list with multiple conditions

    Hi all, I'm trying to get a choosefromlist to work with two conditions.
    the code'I'm using is:
                Dim oCons As SAPbouiCOM.Conditions = oCFL.GetConditions()
                Dim oCon As SAPbouiCOM.Condition = oCons.Add
                Dim oCon2 As SAPbouiCOM.Condition
                oCon.Alias = "ValidFor"
                oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
                oCon.CondVal = "Y"
                oCon2 = oCons.Add
                oCon2.Alias = "PrchseItem"
                oCon2.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
                oCon2.CondVal = "Y"
                oCFL.SetConditions(oCons)
    However I get zero results.
    When I use them one at a time it works fine and I know that there are records in the table that meet the given conditions.
    Can Anybody help me?
    Regards,
    Jeroen Verbeek

    you need to use Relationship
    Dim oCons As SAPbouiCOM.Conditions = oCFL.GetConditions()
    Dim oCon As SAPbouiCOM.Condition = oCons.Add
    oCon.Alias = "ValidFor"
    oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
    oCon.CondVal = "Y"
    oCon.Relationship = BoConditionRelationship.cr_AND;
    oCon = oCons.Add
    oCon.Alias = "PrchseItem"
    oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
    oCon.CondVal = "Y"
    oCFL.SetConditions(oCons)
    Edited by: Danilo Kasparian on Apr 14, 2011 4:08 PM

  • APEX Interactive Report Compute Case with multiple conditions to highlight

    My ultimate is to highligt a row in an interactive report based on two conditions. I didn't see a way to use the highligt feature with two conditions. So I thought I would try to create a computation based on the two conditions. Then use that result for the highligting. Though I don't seem to be a be able to use multiple conditions in my computation Case statement. Is there a different syntax?
    Here is what I have:
    Case
      When  C = 'Open' and  I > 15 Then 'True'
      Else 'False'
    End The error I get is: Invalid computation expression. and
    Application Express 4.0.2.00.07
    Thanks!
    Edited by: cjmartin on Jan 10, 2012 10:57 AM

    I'm surprised no one responded to this. What I did to resolve this issue was create a nested case statement. I don't think this was a good solution, but I can't find anyone else giving input. I know I can create another computational column in the select statement for the report, but the 'Interactive Report' part is where this should be. I want my clients to calculate what they want. Kind of hard when you can not use an 'and' for a range criteria.

  • Script with 2 pages

    hi there,
    I have a script with two pages.........
    both the pages have windows..... header,main,footer.
    script is triggering well with header in both pages. But i can see footer only in second page but not in the first page. How to get the footer in first page also???
    And in the main window apart from the data that flows into second page i also have field headings and eventually they are seen in the first page. I want them to be seen in the second page also. How can I do this?
    any help is appreciated.
    thanks

    yeah santhosh.
    i have created the windows .its working now.
    like u said if i have feild headings in main window.....they are repeating for each and every row....as main window is put in a loop.
    so i created a small window which just carries the field headings.....and then placed in it both the pages. here it solved.
    And coming to footer.......well I have called the write_form for footer after the main window. So technically it has to tigger after main window is triggered. main window is done only in second page  as contents flow to page2 and hence footer was not triggered in first page.
    So i called the write_form of footer before the write_form of main window. eventually footer triggered in both the pages.
    Anyways thanks for your concern and i rewarded the points for your help.

  • Combining Conditions with two DataSources

    Hello All,
    The following Code is to Set two condition to load my data, but my problem is that they are not combining. Is there a way to put two DataSources to a Condition? Or is there a way to Combined them?
    '//Activates Query
    '// getting the data sources from the form
    Set oDBDataSource = Form.DataSources.DBDataSources.Item("RDR1")
    Set oDBDataSource2 = Form.DataSources.DBDataSources.Item("ORDR")
    '// Query the DB Data source
    '// create a new conditions collection
        Set pConds = New Conditions
        Set pConds2 = New Conditions
    '// (CardCode = inputted Cust No) 
        Set pCond2 = pConds2.Add()
        pCond2.BracketOpenNum = 1
        pCond2.Alias = "CardCode" 'FIELD NAME
        pCond2.Operation = co_EQUAL
        pCond2.CondVal = CCode
        pCond2.BracketCloseNum = 1
    '// Execute the query with the conditions collections
        oDBDataSource2.Query (pConds2)
    '// where clause
    '// (LineStatus = 'O')  //O = Open order//
        Set pCond = pConds.Add()
        pCond.BracketOpenNum = 1
        pCond.Alias = "LineStatus" 'FIELD NAME
        pCond.Operation = co_EQUAL
        pCond.CondVal = "O"
        pCond.BracketCloseNum = 1
    '// Execute the query with the conditions collections
        oDBDataSource.Query pConds
    '// set the user data source data
        For i = 0 To oDBDataSource.Size - 1
            oDBDataSource.Offset = i
            oMatrix.AddRow
        Next i

    Hi Laura,
    I think the discussion in this thread will give you the answer:
    JIONs-Query as MatrixDataSourse
    Regards,
    Frank

  • Help with two scripts - Mounting remote DMG and Checking which network I'm connected to

    Hey guys, I need some help with two separate scripts:
    1. The first script I'm trying to create to mount a DMG stored remotely on another Mac using an AppleScript or shell script. Using the following:
    set cmd to "hdiutil mount 'afp://username:[email protected]/Lion/Users/username/Desktop/Test.sparseim age'"
    do shell script cmd
    results in the following error:
    error "hdiutil: mount failed - not recognized" number 1
    I'm not very experienced regarding AppleScript or using hdiutil, could somebody point out what's wrong with my script?
    2. The second script I'm working on to try and essentially prevent the 'Could Not Find Server' Finder dialog when a network mount is unavailable. I guess what I'd like it to do is detect which network I'm connected to, and if I'm connected to the correct network, then mount the shares, otherwise just fail silently without any errors. From the searching I've done, using try statements should do this, but they do not, and I'm still presented with an error dialog after the server cannot be found.
    Does anybody have any suggestions on this script? Also, I've seen some tips regarding detecting which wireless network the Mac is connected to, which could work, but what about when connected via Ethernet?
    Thanks!

    Edit: I need to clarify on my first script request:
    I need to mount the DMG on the remote Mac, not on the Mac I'm running the script from.

  • Parsing logs, need to keep lines matching two conditions [SOLVED]

    I wrote a script that generates a 12 columns in a text file based on parsing my apache logs.  I need to remove any line that match the following two conditions:
    1)     <TAB>200<TAB>
    2)     <TAB>206<TAB>
    Where <TAB> is a literal tab as my other stuff reads tab deliminated files.  The following grep works to match simply '200' or '206' but I can't get the grep syntax correct to match with the trailing and leading tabs.
    grep -w '200\|206' parsed.log
    Any help is appreciated.
    EDIT: Finally!
    grep -E $'\t200\t\|\t206\t' parsed.log
    EDIT2: Rrrr... the above works under zsh but not under bash... what's my problem?
    Last edited by graysky (2013-07-13 16:16:08)

    graysky wrote:
    Thanks for the assistance.  Will mark as solved.
    ...actually, my original thought was flawed.  I actually need to preform this grep query within column #9 in the text file.  Simply doing it on a line-by-line basis does not catch the errors.  I need to some how mate this up with awk.
    EDIT: Here is a sample of the file: http://repo-ck.com/PKG_source/test.txt
    Try
    awk '$9 ~ /20[0,6]/' test.txt
    The sample has only 200 in the 9th column, but I edited it and it worked with 206 too.

Maybe you are looking for