Using a variable in netsh command to set ip address on NIC

hi friends
i wrote an script which gets an input & use that variable to set ip address on NIC. but actually it doesn't set ip address. may you please help me.
my script contains:
$VMNumber=Read-Host "please enter your VM number (for example 2)"
Netsh interface ipv4 set address NIC static 192.168.1.$VMNumber

1. I do not thing that the use of netsh is a right way.
2. You will need a table with MAC address in first column and IP address in second to correctly map IP address to computer. MAC addresses are unique identification.
3. Follow this article including comments and adapt scripts to your task
http://www.powershellpro.com/powershell-tutorial-introduction/powershell-wmi-methods/
HTH
Milos
hi Milos
thank a lot for your useful answer.
but let me say that my need has nothing to do with MAC address.
in my test lab, i need an script which asks the administrators to enter their VM number & it saves this input as a variable & set is as the last octet in their VM IPV4 Address.
so can we tell it as a rule that variables we create in powershell, can't be used inside non cmdlets (inside legacy cmd commands) ?

Similar Messages

  • Using environment variables in RMAN command line

    I'm running Oracle 11gR2 and working in a Solaris 10 environment.
    I am trying to run the rman command by connecting to the target, auxiliary, and catalog by catting out the contents of password files where I have my connect strings stored for each database. Also in there I am trying to use environment variables to reference each database.
    rman target "`cat ${HOME}/password_dir/prod_connect.txt`@${PROD_DB}" auxiliary "`cat ${HOME}/password_dir/stage_connect.txt`@`${STAGE_DB}`" catalog "`cat ${HOME}/password_dir/rman_catalog_connect.txt`@${RMAN_CATALOG_DB}"
    The end result I need is:
    rman target "username/password@db" auxiliary "username/password@db" catalog "username/password@db"
    Is this possible?

    Levi,
    Good idea on the variables. I set up a variable with my connect string including the TNS reference (i.e. user/password@XXX)
    So when I run this:
    rman auxiliary ${AUXILIARY}
    I get this:
    Recovery Manager: Release 11.2.0.2.0 - Production on Wed Jun 13 10:19:44 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-00554: initialization of internal recovery manager package failed
    RMAN-04006: error from auxiliary database: ORA-01031: insufficient privileges
    But if I try to run it without the TNS entry it works. The only issue with that is I need the TNS reference to connect to the database I'm cloning from. Any idea what's going on here?
    Also, the same applies to the TARGET, but oddly enough not the CATALOG. It will connect to my rman catalog using the TNS just fine. The only difference is with the catalog I'm logging in as my rman catalog user. With the TARGET and AUXILIARY I'm logging in as the system user.
    Edited by: Nevin on Jun 13, 2012 8:25 AM

  • Using MDT Variables at a command prompt

    Is it possible to use Task Sequence variables on a "Run Command Line" step?
    I have as my command line:
    loadstate.exe \\%UDShare%\%UDDir% /v:5 /c  /i:"C:\MININT\USMT\X64\MigApp.xml" /i:"C:\MININT\USMT\X64\MigUser.xml" /i:"C:\MININT\USMT\X64\MigDocs.xml" /i:"C:\MININT\USMT\X64\migexcludexternaldrives.xml" /i:"C:\MININT\USMT\X64\migmydocs.xml"
    /i:"C:\MININT\USMT\X64\migwallpaper.xml" /config:"C:\MININT\USMT\X64\ZTIUserState_Config.xml"
    And my Start in is:
    C:\MININT\USMT\X64
    But I receive an error that seems that it is running the command with "\\%UDShare%\%UDDir%" instead of inserting the values for the variables.

    Sorry, I tried that, and it does not work.  I receive the errors:
    Expand a string: loadstate.exe \\%UDShare%\%OSDComputername% /v:5 /c  /i:"C:\MININT\USMT\X64\MigApp.xml" /i:"C:\MININT\USMT\X64\MigUser.xml" /i:"C:\MININT\USMT\X64\MigDocs.xml" /i:"C:\MININT\USMT\X64\migexcludexternaldrives.xml" /i:"C:\MININT\USMT\X64\migmydocs.xml"
    /i:"C:\MININT\USMT\X64\migwallpaper.xml" /config:"C:\MININT\USMT\X64\ZTIUserState_Config.xml"
    Set command line: loadstate.exe \\%UDShare%\%OSDComputername% /v:5 /c  /i:"C:\MININT\USMT\X64\MigApp.xml" /i:"C:\MININT\USMT\X64\MigUser.xml" /i:"C:\MININT\USMT\X64\MigDocs.xml" /i:"C:\MININT\USMT\X64\migexcludexternaldrives.xml" /i:"C:\MININT\USMT\X64\migmydocs.xml"
    /i:"C:\MININT\USMT\X64\migwallpaper.xml" /config:"C:\MININT\USMT\X64\ZTIUserState_Config.xml"
    Start executing the command line: loadstate.exe \\%UDShare%\%OSDComputername% /v:5 /c  /i:"C:\MININT\USMT\X64\MigApp.xml" /i:"C:\MININT\USMT\X64\MigUser.xml" /i:"C:\MININT\USMT\X64\MigDocs.xml" /i:"C:\MININT\USMT\X64\migexcludexternaldrives.xml" /i:"C:\MININT\USMT\X64\migmydocs.xml"
    /i:"C:\MININT\USMT\X64\migwallpaper.xml" /config:"C:\MININT\USMT\X64\ZTIUserState_Config.xml"
    Executing command line: loadstate.exe \\%UDShare%\%OSDComputername% /v:5 /c  /i:"C:\MININT\USMT\X64\MigApp.xml" /i:"C:\MININT\USMT\X64\MigUser.xml" /i:"C:\MININT\USMT\X64\MigDocs.xml" /i:"C:\MININT\USMT\X64\migexcludexternaldrives.xml" /i:"C:\MININT\USMT\X64\migmydocs.xml"
    /i:"C:\MININT\USMT\X64\migwallpaper.xml" /config:"C:\MININT\USMT\X64\ZTIUserState_Config.xml"
    Failed to run the action: Run Command Line. 
    The drive cannot find the sector requested. (Error: 0000001B; Source: Windows)
    The execution of the group (State Restore) has failed and the execution has been aborted. An action failed.
    Operation aborted (Error: 80004004; Source: Windows)
    Failed to run the last action: Run Command Line. Execution of task sequence failed.
    The drive cannot find the sector requested. (Error: 0000001B; Source: Windows)
    Task sequence execution failed with error code 80004005

  • Use Applescript variable in Python command line

    Using automator
    Python Shell Output -> [1,2,3,4,5]
    goes to Applescript
    Run Applescript ->
    on run {input}
        set seq_list_appscript to {}
        do shell script "python -c 'for s in input: print s'"
    end run
    it doesn't work . . . how can I call the "input" which is an Applescript variable within the "do shell script" python command line ?

    If the input is actually a list of items, then you would need to iterate through them or coerce the list to something for the command line.  If the input is just the text "[1,2,3,4,5]", then the variable just needs to be inserted into the text of your script statement - the results of the script are returned by the do shell script command, so they can also be assigned to a variable:
        set whatever to (do shell script "python -c 'for s in " & input & ": print s'")
        display dialog whatever

  • Using Global Variables in Data Quality Address Cleanse Transforms

    I am currently developing in Data Services 12.2.
    I am trying to dynamically populate the List Owner information in the option tabs of the USA Regulatory Address Cleanse by using global variables.  It populates the 3553 with the variable name instead of the value assigned.
    According to the Technical Manual, it is possible to use global variables in Data Quality Address Cleanse transforms:
    However, you can use substitution parameters in all places where global variables are supported, for example:
    Query transform WHERE clauses
    Mappings
    SQL transform SQL statement identifiers
    Flat-file options
    User-defined transforms
    Address cleanse transform options
    Matching thresholds
    Does anyone know if it is possible to use global variables in the option tab of the Address Cleanse; if so, can you describe how it is done?
    Thanks in advance,
    Rick

    Hi,
    U can refer to the following links in help.sap.com
    GlobalContainer Object
    http://help.sap.com/saphelp_nw04/helpdata/en/75/8e0f8f3b0c2e4ea5f8d8f9faa9461a/content.htm
    Container Object
    http://help.sap.com/saphelp_nw04/helpdata/en/78/b4ea10263c404599ec6edabf59aa6c/content.htm
    Also some of the RUN TIME CONSTANTS are available in your BPM. So if you are trying to retrieve those variables in your Mapping(that is used in BPM), also read the following thread.
    Re: Message id in BPM
    Cheers,
    Siva Maranani.

  • [ASK] Set Network Address Restriction With Script

    Hi all, i have a question about set network address restriction.. if i post in wrong category i'm very sorry about it because i don't know where i supposed to post this..
    i need to set network address restriction to every user in my tree..
    the problem is there is hundreds of user that i need to set the restriction.. i think it will take a lot of time if i do it one by one..
    i created the user with script, and i want to ask whether there is a command to set network address restriction with script or maybe there is another simple way to set network address restriction..
    thanks..

    Is the restriction going to be the same for all users? Depending on what
    "script" you use, you should be able to also set the restriction at the
    same time - its just another attribute value to set.
    Peter
    eDirectory Rules!
    http://www.DreamLAN.com

  • Using computer variables in task sequence "Run Command Line"

    I am attempting to deploy VMs through VMware's vRealize Automation tool using CM. The process creates a CM computer object then creates a direct rule on a CM collection for the new computer object. During the creation of the computer object vRA creates computer
    variables provided by me on the computer object. I see the computer object built and i see the custom variables on the computer object:
    Name Value
    dns1 10.10.10.10
    dns2 10.10.10.11
    gateway 10.10.10.1
    ipAddress 10.10.10.2
    netMask 255.255.255.0
    In the task sequence the last step is to "Run Command Line":
    cmd /c netsh int ip set address name="Ethernet0" static %ipAddress% %netMask% %gateway% & cmd /c netsh int ip set dns name="Ethernet0" static %dns1% & cmd /c netsh int ip set dns name="Ethernet0" static %dns2% index=2
    When the TS gets to that step it doesn't substitute the variables in the command with the computer variables listed above. Looking at the smsts logs after the deployment is complete I see lines stating:
    Set Command Line:...
    Start executing command line:...
    Executing command line:...
    ProgramName = ...
    All of those lines show the command exactly as it is above with the %variables% intact.
    The command immediately fails with the error:
    Invalid address parameter (%ipAddress%). It should be a valid IPv4 address.
    Does anyone have a suggestion on why the TS isn't using the variables? I found this article https://technet.microsoft.com/en-us/library/bb693541.aspx but its for 2007 not 2012. I wasn't able to find something comparable for 2012.

    I don't know why anyone here thinks you *need* sccm osd to achieve fully automated customizations.
    Customer selects base image (2008 r2 core, 2008r2 gui, 2012 r2 core, 2012 r2 gui), which should be thin and with zero customizations anyway,
    vaai accelerated clone creates vm,
    ip addr/gateway/dns config is injected with powercli,
    customers config management engine agent of choice is installed via powercli script injection/execution (we have puppet users, ConfigMgr users, saltstack users, IEM users, Cheff users),
    the clone completes in ~2 minutes and a VM is presented to the customer in less than 5 minutes 
    Deploying windows VMs via SCCM OSD is not only slow, but requires dev work on the customer side to get things rolling which wastes everyone's cycles including your own

  • WAD drop-down box and commands on Set Variable values/ Set Filter Values

    Hello to all
    I am confused in WAD and Help online couldn't clarify my concerns. Thus here following issue:
    I am using a WAD, where the data provider (query)  is set dynamically. I would like that
    1 user selects company in  drop-down-box 1
    2 I use commands on drop-down-box 1 to manage the next drop-down-box 2 ( like it becomes input ready)
    3 user selects plant in drop-down-box 2
    4 User selects a tab strip A, where report A of multiple reports is placed. Now in this moment I assign the query A to the data provider A.
    Now my questions:
    - I am not clear how to use the bex-variables required for the query ( like company and plan). If I use in drop-down variables, then I can't set anymore commands
    - What means and makes the command set_variable_state
    - What means and makes the command set_selection_state
    Thanks a lot for your clarification and help
    Christian

    Hi Christian,
    I will try and answer your Qs
    - I am not clear how to use the bex-variables required for the query ( like company and plan). If I use in drop-down variables, then I can't set anymore commands
    >> Can you explain how exactly are you trying to populate the DropDown webitems for Company / Plant data for user-selection.
    - What means and makes the command set_variable_state
    >> SET_VARIABLE_STATE is used to assign input values to your query variables. Here, the command gives you a range of input options to select from such as Characteristic/Text/Formula/Hierarchy Variables & Binding Type Selection. Binding Type Selection in addition gives you more options such as assigning manual input from a Text webitem [ITEM_INPUT], assigning value from another Variable [VARIABLE], or simply assigning the selected value from an underlying Data Provider such as one mapped to a DropDown webitem [DATA_PROVIDER_CHARACTERISTIC].
    - What means and makes the command set_selection_state
    >> SET_SELECTION_STATE is used to assign input values to Characteristics in your query. It serves as a Filter option.
    I think in your case using SET_VARIABLE_STATE makes more sense. You can use Binding Type Selection with [DATA_PROVIDER_CHARACTERISTIC] on both the DropDown webitems to assign the values of Company / Plant to the query on runtime.
    --Priya

  • Executing oracle commands in shell using shell variable

    EOD_TYPE=`sqlplus -s scott/tiger@oracledb <<EOF
    set head off
    set feedback off
    set pages 0
    spool file1.dat
    select to_char(sysdate,'monddyyyy') from dual;
    spool off;
    EOF`
    a=$(head -1 file1.dat | cut -c1-9)
    echo $a
    EOD_TYPE1=`sqlplus -s scott/tiger@oracledb <<EOF1
    spool file2
    select * from $a ;
    EOF1`
    file2 contains "select * from mar132008 ;" instead of the data in the mar132008 table.
    where is the problem.

    I think the -s option might not work in your case.
    Try to run this script with
    sqlplus -s scott/tiger@oracledb @file1.dat
    Also add SPOOL OFF and exit to the end of the second script.
    btw: other useful set commands are
    SET TRIM ON
    SET TRIMSPOOL ON

  • Using a Variable to Substitute the path\filename of a Batch file in the Start_Process Command

    I am trying to write a script that will execute a batch file on a remote Windows server.
    This line below is basically what I'm trying to do and it works without error, however I would like to use a variable for the path\filename of the batch file.
    invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "\\qsc-a-ice01\D$\Test\RunThis.bat" }
    If I try to use a variable as in this example below I receive the error below. The error seems to indicate it's it expecting a "FilePath" parameter. Is this true? How would I change this script to make it work when substituting a variable.
    $MyProcess =  "\\qsc-a-ice01\D$\Test\RunThis.bat"
    Write-Host $MyProcess
    invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "$MyProcess"}
    This is the error text I receive when using a variable:
     PS C:\Windows\system32> D:\Test\ThisWorks.ps1
    \\qsc-a-ice01\D$\Test\RunThis.bat
    Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Supply an argument that is not null or
    empty and then try the command again.
        + CategoryInfo          : InvalidData: (:) [Start-Process], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand
        + PSComputerName        : QSC-A-ICE01
    PS C:\Windows\system32>

    Mike,
    Thanks for providing the link, it was very informative. The link described how to use the args in a ScriptBlock and provided me with an explaination as to why it works the way it does on a remote server. This is my 1st post to the forum and I don't know
    how the points system works yet.
    I would like to split the points , but I don't see that this is possible.
    You're very welcome, I'm glad that the information was helpful.
    You can mark as many posts as answers as you'd like, there's not a restriction on only having a single answer per thread. You certainly don't have to though, David's answer is more than sufficient to help any future people who find this thread.
    Also, on a side note, you may want to post in the thread below. Posting there will get your account verified so you'll be able to post links and images.
    http://social.technet.microsoft.com/Forums/en-US/200c33c9-abe9-494a-953a-bf53fccb3c76/verify-your-account-11?forum=reportabug
    (Future people - don't use that link.
    Click here and look for the current thread as a sticky.)
    Don't retire TechNet! -
    (Don't give up yet - 12,575+ strong and growing)

  • Using a variable as the comparison set with the IN clause

    I am attempting to use a variable as the comparison set in an IN clause:
    if <var> is not null and <var> in (<variable>) then ...
    if <var> = 'X' and <variable> = 'X','Y' this statement evaluates to FALSE. If, however, I write
    if <var> is not null and <var> in ('X','Y') then ...
    the statement evaluates to TRUE. Is there a way to force evaluation of a variable prior to executing the statement?

    Kumar
    That is neat trick and an good example of lateral thinking. However, there is a slight problem with it in that this is true:
    instr('1APC2', 'APC')
    whereas this is false
    'APC' IN ('1APC2')
    However, it did inspire me to produce an even neater trick:
    create or replace function my_in
    (in_value IN varchar2, in_string_list IN varchar2)
    RETURN boolean
    AS
    larray_string DBMS_UTILITY.uncl_array;
    ln_count INTEGER;
    return_value BOOLEAN := FALSE;
    lv_comparator VARCHAR2(4000);
    BEGIN
    DBMS_UTILITY.comma_to_table(in_string_list, ln_count, larray_string);
    FOR rownum IN 1..ln_count
    LOOP
    IF larray_string(rownum) = in_value
    THEN
    return_value := TRUE;
    EXIT;
    END IF;
    END LOOP;
    RETURN return_value;
    END;
    Note that the in_string list parameter must be COMMA separated, and spaces will be treated as values. Hence
    declare
    lb boolean;
    begin
    lb := my_in('APC', 'DEF,APC,ABC');
    if lb = TRUE
    THEN
    dbms_output.put_line('FOUND');
    else
    dbms_output.put_line('NOT FOUND');
    end if;
    lb := my_in('APC', 'DEF, APC, ABC');
    if lb = TRUE
    THEN
    dbms_output.put_line('FOUND');
    else
    dbms_output.put_line('NOT FOUND');
    end if;
    end;
    produces the following output:
    SQL> @tstrun
    FOUND
    NOT FOUND
    PL/SQL procedure successfully completed.
    SQL>
    Kindest regards, APC

  • Write-EventLog from a command line using a variable for -Message

    My apologies for the possibly confusing title of this post, so let me explain...
    My ultimate goal is to capture log information during the execution of a batch script and write it to the Application log.  Simple, you might think?  I couldn't figure it out in batch so gave up and moved on to try using PowerShell via
    the @powershell command.
    I started with the following test, which worked like a charm:
    @PowerShell -NoProfile -command "Write-EventLog -LogName Application -Source MyApp -EntryType Information -EventID 99 -Message "Test1" -ComputerName MyServer"
    Great I thought, now how to capture multiple "events" as my batch script executes so that I can write them all in one go to the Application log using a single @powershell command.  Capturing multiple lines of text in an environment variable
    was a struggle and I wasn't even sure if I could then use the environment variable in the PowerShell command, so I tried writing the events to a text file with the intend of reading that text file using Get-Content, and then writing it to the event log.
    So test #2 went like this:
    @PowerShell -NoProfile -command "$OutText = 'Some text';Write-EventLog -LogName Application -Source MyApp -EntryType Information -EventID 99 -Message $OutText -ComputerName MyServer"
    This worked, and "Some text" was successfully written to the event log entry, so the last step was to read my entries from the text file and write them instead:
    For reference, the text file looked like this:
    Test Entry 1
    Test Entry 2
    Test Entry 3 
    @PowerShell -NoProfile -command "$OutText = Get-Content .\TestLog.txt;Write-EventLog -LogName Application -Source MyApp -EntryType Information -EventID 99 -Message $OutText -ComputerName MyServer"
    Unfortunately I failed at the last hurdle as PowerShell didn't seem to like, I am guessing, the CRLFs in the text file?
    Write-EventLog : Cannot convert 'System.Object[]' to the type 'System.String'
    required by parameter 'Message'. Specified method is not supported.
    At line:1 char:211
    + ... yServer -Message $OutText
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Write-EventLog], Parameter
       BindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Comma
       nds.WriteEventLogCommand
    Any suggestions on how to solve my dilemma, either by solving the last step, or maybe by taking a different approach?
    Many thanks, in advance,
    Andy

    Here is how we write to the event log from a batch file.  It is easy and more flexible than howyou are doing this:
    eventcreate /?
    eventcreate /L application /SO MyApp /ID 99 /D %messagetext% /S MyServer
    Adding one big block of text to the event log is not how the EL can work.  The message size is limited.
    The Event Log should not be used as a general tracing log on a regular basis.  It should be used to log errors that are critical and to log critical small pieces of information.
    Why use batch if you have access to PowerShell. It is far less flexible and muc harder to manage.
    ¯\_(ツ)_/¯

  • How to use a variable to specify the color when setting an attribute

    Hi
    We are using BI Publisher (XDO) embedded in e-Business Suite. So we are effectively on version 5.6.3.
    I would like to conditionally set the background-color attribute of cells in a table by using a variable reference; something like this (the ways in which I have tried):
    <?attribute@incontext:background-color;$exEmpBGColor?>
    <?attribute@incontext:background-color;'{$exEmpBGColor}'?>
    The 'standard' way of doing this would be:
    <?attribute@incontext:background-color;'#CCCCFF'?>
    Can anybody please help? (i.e. is this even possible?)

    Thanks that works.
    I was using a variable, so I adapted your example to use the variable, not an element.
    <xsl:attribute xdofo:ctx="block" name="background-color"><xsl:value-of select='$exEmpBackgroundColour' /></xsl:attribute>
    Regards

  • Using substitution variable with multiple values in Maxl Command

    Hi All,
    Is there any option to use multiple values in 1 substitution variable and use them in a Maxl command.
    alter database $app_name.$db_name clear data in region '{CrossJoin(CrossJoin(CrossJoin({StrTOMbr(&Months)},{XXX, YYY}),{StrTOMbr(&CURYR)}), {ZZZ})}'physical;
    In the above case
    Maxl is not working if I have multiple months in &Months Substitution variable.
    Let me know if there is an alternate option to implement this.
    Thanks
    Sathish

    What is the value of &Months?
    If you put that exact value into the code, does it work?
    Regards,
    Cameron Lackpour

  • Set "url" in HTTPService using String variable

    Hi,
    How can I set "url" in HTTPService using String variable (see below). I've tried different formats of string & variable concatenations.
    privtate var myurl:String = "http://localhost/";
        <mx:HTTPService id="post_submit_service"
            url="{myurl+'test.php'}"
            method="POST"
            resultFormat="text"
          result="result_handler(event)"
          fault="fault_handler(event)">
            <mx:request xmlns="">
          </mx:request>
        </mx:HTTPService>
    Thanks,
    ASM

    try following:
    url="{myurl}test.php"

Maybe you are looking for

  • Howto export and import SLD data to different SLD's

    Hi All, I have a landcape with 4 SLD's. A central SLD within Solution Manager and 3 SLD's for resp. XI dev,qas,prd. The central SLD is version 7.0 and the XI versions are 2.2. (model versions are the same, CR are different -> XI SAP_CR 2.18 -> Solman

  • Every video put into Final Cut Pro exports in horrible quality regardless of format/settings.

    Hello fellow Mac enthusiasts, I'm having a problem which may or may not have been plaguing my studio since day one. Every video that we edit in Final Cut Pro exports in MUCH lower quality than it was when it was imported, not only that, the file size

  • BBM display picture is blurry! Can not rotate and zoom. Update please

    Hi.. Please help me.. I just bought blackberry q10 but I really don't like how the BBM works. How to fix a blurry display picture on bbm? I'm using blackberry for a long time and I need to share and update my pictures to my family and my friends whic

  • Version 7.0.1.8

    I had 7.0 but removed it and went back to version 6.04. When version 7.01.8 came out I went ahead and downloaded it and my first two songs I played started skipping again. The playback for my downloaded videos and podcasts still have the same problem

  • How to display a file (.doc, .xls, .ppt, ...) ?

    I need to display a word document or an excel document? How can can I do it ?? Thanks for any help !!