Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

not using variables

Closed Thread
 
Thread Tools Display Modes
Old 01-09-2007   #1 (permalink)
IT Staff
Guest
 
Posts: n/a

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


 
Old 01-09-2007   #2 (permalink)
Keith Hill [MVP]
Guest
 
Posts: n/a

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


 
 
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
$Variables Guy Thomas PowerShell 5 06-01-2007 05:05 AM
Re: list env variables Keith Hill PowerShell 4 01-04-2007 11:23 AM
Should this work with variables Marco Shaw PowerShell 2 12-04-2006 10:29 AM
Sundeep Raina(Iopsis): Is variables being handled in Workflow and How to declare New Variables sunny Avalon 0 06-30-2006 01:31 AM








Vistax64.com 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 2005-2008

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 47 48 49