Run command in two powershell

0

Good morning:

I want to execute a powershell code in "Microsoft DOS" and the result of this is to put it in a variable and then use it in another command, which I could only run in DOS, maybe it could be executed by powershell ...

Specifically with the powershell command:

([datetime] "01/01/2017" - [datetime] :: Now)

This gives me back the difference of the current day with respect to the one I put.

Days: -345 Hours: -13 Minutes: -40 Seconds: -46 Milliseconds: -709 Ticks: -298572467097274 TotalDays: -345,569985066289 TotalHours: -8293,67964159094 TotalMinutes: -497620,778495457 TotalSeconds: -29857246,7097274 TotalMilliseconds: -29857246709 , 7274

I want to stay with the milliseconds without decimals and then pass it with a variable by DOS to another command. Also if you can calculate the milliseconds in DOS between two dates, it would be worth ... or do everything in powershell ...

Does anyone think of where I can start?

Greetings

    
asked by FRY FUTURAMA 12.12.2017 в 13:45
source

1 answer

0

Fixed, if it is for the people pff ... I put it in case someone needs some day ... we create a script in Powershell

STEP 1: Declare variables and give them the value

$ path="C: \ Program Files \ Oracle \ VirtualBox" #path where virtualbox is located

$ name_VM="NAMEMAQUINAVIRTUAL" #Name of the machine in virtualbox

$ date="01/01/2017" #Date that we want to initialize the virtual machine

$ time = ([datetime] $ date - [datetime] :: Now) #We save the entire subtraction in a variable

$ time = $ time.TotalMilliseconds #We now save the variable only milliseconds

$ time = [string] $ time #We convert to STRING for handling

$ time = $ time.split (".") [0] #We are left with the first part of the split (.)

STEP 2: We enter the correct route

cd "$ route" #We enter the route

STEP 3: Execute a command to synchronize the machine by passing the variables name_VM

. \ VBoxManage setextradata $ VM_name "VBoxInternal / Devices / VMMDev / 0 / Config / GetHostTimeDisabled" 1

STEP 4: We execute the second command to put the date and time we want to change to the machine

. \ VBoxManage modifyvm $ VM_name - biossystemtimeoffset $ time

And then for more convenience create a bat that executes the script:

@echo off cd C: \ Users \ Developer \ Desktop \ Virtual Machine Directory powershell Set-ExecutionPolicy Unrestricted powershell. \ ChangeHora.ps1

    
answered by 27.12.2017 / 17:57
source