Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - Add string to variable with no line breaks

$
0
0

I am trying to do what I thought would be very simple and join a few strings together in a powershell script.  Here's what I have tried so far.

Example1: $userprofile = "C:\users\" + $user + "\"

Example2: $userprofile = [String]::Join("C:\users\", $user, "\")

Example3: $userprofile = [String]::Concat("C:\users\", $user, "\")

The result from each of these examples is the same, the first string ("C:\users\") and string variable ($user) are joined properly, but the last string ("\") is added after a line break so the output looks like this:

C:\users\daniel.smith

\

FYI: I know that I could just use the $userprofile system variable but the script will not be running under the logged on user's user context, however I still need to access the logged on user's profile, so I am getting the current user from WMI and building the userprofile path from that.

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>