none
Pass the output of a command to a variable RRS feed

  • Question

  • Hi

    I would like to create a variable from the following batch command output which can then be used as part of another command.

    systeminfo | find /i "install date"

    I would like to take the output of this command and then create a registry entry with that.



    • Edited by sfG-Shane Thursday, February 16, 2017 4:29 PM Clear up
    Thursday, February 16, 2017 4:15 PM

Answers

  • A colleague of mine was able to help me out with this. The working command is shown below.

    @Echo off

    for /f "tokens=1-4" %%g in ('powershell ([WMI]''^).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem^).InstallDate^)') do set d8=%%g %%h %%i

    REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom5 /t REG_SZ /d %d8% /f

    :End 

    Tuesday, February 21, 2017 12:04 PM

All replies

  • You have a lot of junk characters in your post. (Take a look at it.)

    Also, remember that we can't read your mind nor read your screen.

    Try asking your question again, and be very specific about what precisely you are asking about.


    -- Bill Stewart [Bill_Stewart]

    Thursday, February 16, 2017 4:22 PM
    Moderator
  • Thanks,

    I'm sorry I didn't notice the junk in the post.

    I have tried to elaborate on my question with more information.

    Thursday, February 16, 2017 4:30 PM
  • You don't need a registry entry. Just ask WMI what the install date is. PowerShell Example:


    $instDateString = Get-WmiObject Win32_OperatingSystem -ComputerName computer |
      Select-Object -ExpandProperty InstallDate
    [Management.ManagementDateTimeConverter]::ToDateTime($instDateString)
    


    -- Bill Stewart [Bill_Stewart]

    Thursday, February 16, 2017 4:43 PM
    Moderator
  • Hi Bill,

    The value which is returned needs to be added as a registry entry for the management software to use it afterwards.

    An example of one that has been used previously is below:

    @Echo Off

    FOR /F "TOKENS=2* DELIMS=:" %%A IN ('omreport chassis remoteaccess ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B

    REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom2 /t REG_SZ /d %IPADDR% /f

    :End

    Monday, February 20, 2017 12:26 PM
  • A colleague of mine was able to help me out with this. The working command is shown below.

    @Echo off

    for /f "tokens=1-4" %%g in ('powershell ([WMI]''^).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem^).InstallDate^)') do set d8=%%g %%h %%i

    REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom5 /t REG_SZ /d %d8% /f

    :End 

    Tuesday, February 21, 2017 12:04 PM