I am getting an item from Sitecore, then taking the return and messing with the FullName to build the URL.
Import-Module -Name SPE
$Id = [Some Id]
$session = New-ScriptSession -Username [un]-Password [pw] -ConnectionUri http://sitecorehostname
$Item = Invoke-RemoteScript -Session $session -ScriptBlock {
$item = Get-Item -Path "master:/media library" -Id "$($params.id)"
$item | Get-Member
$item
} -Arguments @{"id"=$Id}
Stop-ScriptSession -Session $session
$Url = $Item.FullPath
$Url = $Url -replace "^/sitecore/shell/sitecore/", "/-/"
$Url = $Url -replace "^/sitecore/", "/-/"
$Url = $Url -replace "^/media library/", "/media/"
$tempKey = $Item.Key + "/"
$Url = $Url -replace $tempKey, $Item.Key
$Url = "http://sitecorehostname" + $Url
At the end of this code, the value of $Url is "http//sitecorehostname[About 1000 spaces]+[$Item.FullPath with replaced strings]
What confuses me is if I take the text of $Item.FullPath and just run some test code below:
$Url = "/sitecore/media library/Images/ThatOneImage"
$Url = $Url -Replace "^/sitecore/shell/sitecore/", "/-/"
$Url = $Url -Replace "^/sitecore/", "/-/"
$Url = $Url -Replace "^/media library/", "/media/"
etc...
I get a proper URL without all the extra spaces. What am I missing?