When I use Write-Host
within a Foreach-Object
, I get an unnecessary space in the output.
write-host \"http://contoso.com/personal/\
Just do it without write-host
:
"http://contoso.com/personal/{0}" -f $_.ADUserName
This is happening because Write-Host is considering your constant string and your object to be two separate parameters -- you aren't actually joining the strings together the way you're calling it. Instead of calling it this way, actually concatenate the strings:
write-host "http://contoso.com/personal/$($_.ADUserName)"
or
write-host ("http://contoso.com/personal/" + $_.ADUserName)
or
write-host ("http://contoso.com/personal/{0}" -f $_.ADUserName)