Converting result of the output to needed format

I get the output of the variable $WinInsDate in the format "20120509120504.000000 +180"

how can I convert it to a format similar to output command

 Get-Date -DisplayHint date ?
nesher13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Where are you getting that date from?  Looks like time from some WMI queries.
$a = (Get-WmiObject Win32_OperatingSystem)
$a.converttodatetime($a.installdate)

Open in new window


See here for a little background info.
http://technet.microsoft.com/en-us/magazine/2008.12.heyscriptingguy.aspx?pr=PuzzleAnswer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
WMI dates don't have the additonal space between time and timezone offset (in minutes). Either the format above is wrong, or there is a different source ...

If you want to do it the hard, but most flexible way:
invoke-expression ( "20120509120504.000000 +180" -replace '^(\d{4})(\d{2})(\d{2})(\d\d)(\d\d)(\d\d)\.\d+ \+(\d+)', '(get-date -date "$2/$3/$1 $4:$5:$6").AddMinutes($7)')

Open in new window

I've ignored the milli/microseconds stuff.
0
nesher13Author Commented:
to footech

how can I convert the resulting format into a format mm/dd/yyyy ?
0
Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Both expressions will result in a datatime, which again can be formatted by e.g. stuffing into get-date -format .... or using the -f operator (which will automatically use the date format set up in the OS):
  get-date -format 'MM/dd/yyyy' $yourDateTime
   '{0:d}' -f $yourDateTime
0
nesher13Author Commented:
I found a pretty simple solution to the second part of the question

PS C:\>$a = (Get-WmiObject Win32_OperatingSystem)

PS C:\>$a.converttodatetime($a.installdate)

Sunday, August 04, 2013 5:46:45 PM

PS C:\>$a.converttodatetime($a.installdate) | get-date -format d

8/4/2013
0
nesher13Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for nesher13's comment #a39520350
Assisted answer: 500 points for footech's comment #a39517538

for the following reason:

footech answer gave me the basis for solving the problem
0
nesher13Author Commented:
footech answer gave me the basis for solving the problem
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
So your date literal "20120509120504.000000 +180" was wrong? The corresponding WMI date literal is "20120509120504.000000+180" (no space, as mentioned above).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.