Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple concatenate problem

150 views
Skip to first unread message

TFTAJL...@spammotel.com

unread,
Jan 24, 2009, 7:01:40 PM1/24/09
to
Could someone please suggest how I can concatenate an expanded
environment variable with a string inside a cmdlet parameter? I want
to use the AppData environment variable contents and add some sub-
folder specs to it as part of a Copy-Item destination parameter:

copy-item -Path <network folder> -Destination env:AppData + "\Roaming
\Microsoft"

As you no doubt guessed, this is my first foray into Powershell.

Thanks,

Marco Shaw [MVP]

unread,
Jan 24, 2009, 9:13:53 PM1/24/09
to
TFTAJL...@spammotel.com wrote:
> Could someone please suggest how I can concatenate an expanded
> environment variable with a string inside a cmdlet parameter? I want
> to use the AppData environment variable contents and add some sub-
> folder specs to it as part of a Copy-Item destination parameter:
>
> copy-item -Path <network folder> -Destination env:AppData + "\Roaming
> \Microsoft"

How about this:

copy-item -path <network folder> -dest (join-path $env:appdata
"\Roaming\Microsoft") -whatif

Using "-whatif" allows you to see what would happen if the command was
actually run.

Marco


--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition (due December
15th, 2008)
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

Shay Levy [MVP]

unread,
Jan 25, 2009, 2:33:22 AM1/25/09
to

copy-item -Path <network folder> -Destination "$env:AppData\Roaming\Microsoft"


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

Joel (Jaykul) Bennett

unread,
Jan 25, 2009, 6:08:25 PM1/25/09
to
> How about this:
>
> copy-item -path <network folder> -dest (join-path $env:appdata
> "\Roaming\Microsoft") -whatif
>

I'll back up Marco on this one ... using Join-Path is safer, and will
adjust for when you have too many (or too few) slashes (ie: if the
environment variable has a trailing slash and you add one in your
string) so it's safer than just concatenating strings.

However, if you're sure you don't need the extra safety ... it's
certainly simpler to just use "$env:AppData\Roaming\Microsoft" or,
more correctly, the curly-brace content notation: "${Env:AppData}
\Roaming\Microsoft"

--
Joel

TFTAJL...@spammotel.com

unread,
Jan 27, 2009, 12:48:25 AM1/27/09
to
On Jan 25, 3:08 pm, "Joel (Jaykul) Bennett" <Jay...@HuddledMasses.org>
wrote:

Thanks for all your replies, folks. It's working now.

0 new messages