header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Changing Read-Host Input Type
Last Post 20 Nov 2008 07:05 PM by Shay. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
20 Nov 2008 04:21 PM  
Hi,

Is there a way to change the type of the input from a read-host command from a system.string to a system.datetime type?

I have created a script to query AD for users created between 2 dates but the problem is (I think) that powershell is comparing the input type to a property that is is a different type.

my script is below:

#This script will list new accounts created between 2 days and then count them.

$start = (read-host "First date dd/mm/yyyy hh/mm/ss?")
$finish = (read-host "Last date dd/mm/yyyy hh/mm/ss?")
Write-host "This script will display all accounts created between $start and $finish. Please wait a few minutes" -fore yellow

$TotalAccountsCreated = Get-QADUser -SizeLimit 0 | Where {$_.whencreated -lt $start} | where {$_.whencreated -ge $finish} | select Name,Company
$TotalAccountsCreated

Write-host "There have been" $totalaccountscreated.count " created between $start and $finish" -fore red

Regards

Lee
EBGreenUser is Offline
New Member
New Member
Posts:62
Avatar

--
20 Nov 2008 04:27 PM  
[datetime]$foo = Read-Host "Enter a date"

SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
20 Nov 2008 06:06 PM  
Of course. I should have known that one.

Thanks for your help.
ShayUser is Offline
Basic Member
Basic Member
Posts:272
Avatar

--
20 Nov 2008 07:05 PM  
Your command can be more efficient using one where-object call only

... | Where { ($_.whencreated -lt $star) -AND ($_.whencreated -ge $finish) }
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer