Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - ConverttoDateTime Question

Reply
 
Old 05-27-2008   #1 (permalink)
TimParker


 
 

ConverttoDateTime Question

I am working on writing a simple script to get the last reboot date of
certain workstations and servers on my network. I am having issues
with the Converttodatetime function. I am doing the following.

$machines = get-qadcomputer -searchroot 'Name of OU Here' | for each
{$_.name}
{
$wmi = gwmi -class Win32_operatingSystem -Computername $machines
$reboottime = converttodatetime ($wmi.lastbootuptime)
}

when I run this it tells me that "the term converttodatetime is not
recognized as a cmdlet, function, operable program or script file.
Verify the term and try again.

I have searched the archives here and the blogs out there and all the
examples that I have seen do the same type of thing. I have also taken
out the first line and hardcoded a machine name in place of $machines
to make sure that wasn't the problem.

What am I missing?

TIA.

My System SpecsSystem Spec
Old 05-27-2008   #2 (permalink)
TimParker


 
 

Re: ConverttoDateTime Question

I apparently have tried everything, BUT what you just recommended as
it obviously worked.

Thanks Shay.


On May 27, 5:45 pm, Shay Levi <n...@xxxxxx> wrote:
Quote:

> convertToDateTime is a method of the $wmi object, you need to prepend $wmi:
>
> $wmi.converttodatetime($wmi.lastbootuptime)
>
> ---
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
>
Quote:

> > I am working on writing a simple script to get the last reboot date of
> > certain workstations and servers on my network. I am having issues
> > with the Converttodatetime function. I am doing the following.
>
Quote:

> > $machines = get-qadcomputer -searchroot 'Name of OU Here' | for each
> > {$_.name}
> > {
> > $wmi = gwmi -class Win32_operatingSystem -Computername $machines
> > $reboottime = converttodatetime ($wmi.lastbootuptime)
> > }
> > when I run this it tells me that "the term converttodatetime is not
> > recognized as a cmdlet, function, operable program or script file.
> > Verify the term and try again.
>
Quote:

> > I have searched the archives here and the blogs out there and all the
> > examples that I have seen do the same type of thing. I have also taken
> > out the first line and hardcoded a machine name in place of $machines
> > to make sure that wasn't the problem.
>
Quote:

> > What am I missing?
>
Quote:

> > TIA.
My System SpecsSystem Spec
Old 05-27-2008   #3 (permalink)
TimParker


 
 

Re: ConverttoDateTime Question

Very nice. I don't totally understand all of your select statement
right now but my Powershell TFM book should be here in a day or two so
I am starting my library and learning! None of the bookstores around
me seem to carry anything that I want! (

I was close in what I had in that I was just outputting $machines,
$reboottime


On May 27, 5:58 pm, Shay Levi <n...@xxxxxx> wrote:
Quote:

> You're welcome
>
> BTW, you can generate a table of computerName (CSName) and last reboot time
> for all machines like so:
>
> $machines = get-qadcomputer -searchroot 'Name of OU Here' | foreach {$_.name}
> gwmi -class Win32_operatingSystem -computerName $machines | select CSName,
> @{n="LastBootUptime";e={ $_.converttodatetime($_.lastbootuptime)}}
>
> ---
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
>
Quote:

> > I apparently have tried everything, BUT what you just recommended as
> > it obviously worked.
>
Quote:

> > Thanks Shay.
>
Quote:

> > On May 27, 5:45 pm, Shay Levi <n...@xxxxxx> wrote:
>
Quote:
Quote:

> >> convertToDateTime is a method of the $wmi object, you need to prepend
> >> $wmi:
>
Quote:
Quote:

> >> $wmi.converttodatetime($wmi.lastbootuptime)
>
Quote:
Quote:

> >> ---
> >> Shay Levi
> >> $cript Fanatichttp://scriptolog.blogspot.com
> >>> I am working on writing a simple script to get the last reboot date
> >>> of certain workstations and servers on my network. I am having
> >>> issues with the Converttodatetime function. I am doing the
> >>> following.
>
Quote:
Quote:

> >>> $machines = get-qadcomputer -searchroot 'Name of OU Here' | for each
> >>> {$_.name}
> >>> {
> >>> $wmi = gwmi -class Win32_operatingSystem -Computername $machines
> >>> $reboottime = converttodatetime ($wmi.lastbootuptime)
> >>> }
> >>> when I run this it tells me that "the term converttodatetime is not
> >>> recognized as a cmdlet, function, operable program or script file.
> >>> Verify the term and try again.
> >>> I have searched the archives here and the blogs out there and all
> >>> the examples that I have seen do the same type of thing. I have also
> >>> taken out the first line and hardcoded a machine name in place of
> >>> $machines to make sure that wasn't the problem.
>
Quote:
Quote:

> >>> What am I missing?
>
Quote:
Quote:

> >>> TIA.
My System SpecsSystem Spec
Old 05-27-2008   #4 (permalink)
Shay Levi


 
 

Re: ConverttoDateTime Question


convertToDateTime is a method of the $wmi object, you need to prepend $wmi:

$wmi.converttodatetime($wmi.lastbootuptime)


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I am working on writing a simple script to get the last reboot date of
> certain workstations and servers on my network. I am having issues
> with the Converttodatetime function. I am doing the following.
>
> $machines = get-qadcomputer -searchroot 'Name of OU Here' | for each
> {$_.name}
> {
> $wmi = gwmi -class Win32_operatingSystem -Computername $machines
> $reboottime = converttodatetime ($wmi.lastbootuptime)
> }
> when I run this it tells me that "the term converttodatetime is not
> recognized as a cmdlet, function, operable program or script file.
> Verify the term and try again.
>
> I have searched the archives here and the blogs out there and all the
> examples that I have seen do the same type of thing. I have also taken
> out the first line and hardcoded a machine name in place of $machines
> to make sure that wasn't the problem.
>
> What am I missing?
>
> TIA.
>

My System SpecsSystem Spec
Old 05-27-2008   #5 (permalink)
Shay Levi


 
 

Re: ConverttoDateTime Question

You're welcome

BTW, you can generate a table of computerName (CSName) and last reboot time
for all machines like so:

$machines = get-qadcomputer -searchroot 'Name of OU Here' | foreach {$_.name}
gwmi -class Win32_operatingSystem -computerName $machines | select CSName,
@{n="LastBootUptime";e={ $_.converttodatetime($_.lastbootuptime)}}




---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I apparently have tried everything, BUT what you just recommended as
> it obviously worked.
>
> Thanks Shay.
>
> On May 27, 5:45 pm, Shay Levi <n...@xxxxxx> wrote:
>
Quote:

>> convertToDateTime is a method of the $wmi object, you need to prepend
>> $wmi:
>>
>> $wmi.converttodatetime($wmi.lastbootuptime)
>>
>> ---
>> Shay Levi
>> $cript Fanatichttp://scriptolog.blogspot.com
Quote:

>>> I am working on writing a simple script to get the last reboot date
>>> of certain workstations and servers on my network. I am having
>>> issues with the Converttodatetime function. I am doing the
>>> following.
>>>
>>> $machines = get-qadcomputer -searchroot 'Name of OU Here' | for each
>>> {$_.name}
>>> {
>>> $wmi = gwmi -class Win32_operatingSystem -Computername $machines
>>> $reboottime = converttodatetime ($wmi.lastbootuptime)
>>> }
>>> when I run this it tells me that "the term converttodatetime is not
>>> recognized as a cmdlet, function, operable program or script file.
>>> Verify the term and try again.
>>> I have searched the archives here and the blogs out there and all
>>> the examples that I have seen do the same type of thing. I have also
>>> taken out the first line and hardcoded a machine name in place of
>>> $machines to make sure that wasn't the problem.
>>>
>>> What am I missing?
>>>
>>> TIA.
>>>

My System SpecsSystem Spec
Old 05-28-2008   #6 (permalink)
Shay Levi


 
 

Re: ConverttoDateTime Question



You can get more info on 'Calculated Properties' here:
http://www.microsoft.com/technet/scr...pstip0425.mspx

Sapien's Powershell TFM is a great book! You can find more info on this topic
in Chapter 6
'Cmdlets to Group, Sort, Format, Export, and More'


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Very nice. I don't totally understand all of your select statement
> right now but my Powershell TFM book should be here in a day or two so
> I am starting my library and learning! None of the bookstores around
> me seem to carry anything that I want! (
>
> I was close in what I had in that I was just outputting $machines,
> $reboottime
>
> On May 27, 5:58 pm, Shay Levi <n...@xxxxxx> wrote:
>
Quote:

>> You're welcome
>>
>> BTW, you can generate a table of computerName (CSName) and last
>> reboot time for all machines like so:
>>
>> $machines = get-qadcomputer -searchroot 'Name of OU Here' | foreach
>> {$_.name} gwmi -class Win32_operatingSystem -computerName $machines |
>> select CSName, @{n="LastBootUptime";e={
>> $_.converttodatetime($_.lastbootuptime)}}
>>
>> ---
>> Shay Levi
>> $cript Fanatichttp://scriptolog.blogspot.com
Quote:

>>> I apparently have tried everything, BUT what you just recommended as
>>> it obviously worked.
>>>
>>> Thanks Shay.
>>>
>>> On May 27, 5:45 pm, Shay Levi <n...@xxxxxx> wrote:
>>>
>>>> convertToDateTime is a method of the $wmi object, you need to
>>>> prepend $wmi:
>>>>
>>>> $wmi.converttodatetime($wmi.lastbootuptime)
>>>>
>>>> ---
>>>> Shay Levi
>>>> $cript Fanatichttp://scriptolog.blogspot.com
>>>>> I am working on writing a simple script to get the last reboot
>>>>> date of certain workstations and servers on my network. I am
>>>>> having issues with the Converttodatetime function. I am doing the
>>>>> following.
>>>>>
>>>>> $machines = get-qadcomputer -searchroot 'Name of OU Here' | for
>>>>> each
>>>>> {$_.name}
>>>>> {
>>>>> $wmi = gwmi -class Win32_operatingSystem -Computername $machines
>>>>> $reboottime = converttodatetime ($wmi.lastbootuptime)
>>>>> }
>>>>> when I run this it tells me that "the term converttodatetime is
>>>>> not
>>>>> recognized as a cmdlet, function, operable program or script file.
>>>>> Verify the term and try again.
>>>>> I have searched the archives here and the blogs out there and all
>>>>> the examples that I have seen do the same type of thing. I have
>>>>> also
>>>>> taken out the first line and hardcoded a machine name in place of
>>>>> $machines to make sure that wasn't the problem.
>>>>> What am I missing?
>>>>>
>>>>> TIA.
>>>>>

My System SpecsSystem Spec
Old 05-28-2008   #7 (permalink)
TimParker


 
 

Re: ConverttoDateTime Question

Now I understand the SELECT statement you used! Thanks again Shay. I
appreciate your helpfulness and pointers to the correct info!

Tim


On May 28, 3:31*am, Shay Levi <n...@xxxxxx> wrote:
Quote:

> You can get more info on 'Calculated Properties' here:http://www.microsoft..com/technet/sc.../pstips/apr08/...
>
> Sapien's Powershell TFM is a great book! You can find more info on this topic
> in Chapter 6
> 'Cmdlets to Group, Sort, Format, Export, and More'
>
> ---
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
set up question Vista mail
escape character question - hopefully an easy question PowerShell
converttodatetime from wmi class not working PowerShell
vista genral question and ultimate question Vista General
Dual boot system question and family deal discount question Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46