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 - not using variables

Reply
 
Old 01-09-2007   #1 (permalink)
IT Staff


 
 

not using variables

$today=get-date
write-host "`nToday Date :" $today

the above works fine.

However i wish to shorten the code to :

write-host "`nToday Date :" + get-date

but i could not get-date ...in vbscript we can use & to concantenate, pls
advice



My System SpecsSystem Spec
Old 01-09-2007   #2 (permalink)
Keith Hill [MVP]


 
 

Re: not using variables

"IT Staff" <jkklim@hotmail.com> wrote in message
news:eCQ8aiGNHHA.1280@TK2MSFTNGP04.phx.gbl...
> $today=get-date
> write-host "`nToday Date :" $today
>
> the above works fine.
>
> However i wish to shorten the code to :
>
> write-host "`nToday Date :" + get-date
>
> but i could not get-date ...in vbscript we can use & to concantenate, pls
> advice


Once you have started a string like this, the PowerShell parser is operation
in expression mode so it won't interpret "get-date" as go execute the
command get-date. You can instruct the parser to begin a new parser context
to get it to intrepret get-date as a command like so:

"`nToday Date :" + (get-date)

But another, more terse way to do this is to do the expansion within the
string using a subexpression like so:

"`nToday Date : $(get-date)"

--
Keith


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
SQL query with PS variables PowerShell
math with "GB/MB/KB" in variables fails, without variables works? PowerShell
$Variables PowerShell


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