Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to remove spaces/white spaces in Environment variables.

$
0
0

Hi..

I have requirement in which to remove the spaces with the short file name from the Environment Variables

Below is my code..but it is throwing an error..please suggest.

$fso = New-Object -comobject "scripting.filesystemobject"

$shortpaths = @();

foreach ($path in $env:Path.Split(";")) 

{

    $shortpaths += $fso.GetFolder($path).ShortPath;

    }

$shortpaths -join ";";

$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"

$OldPath = (Get-ItemProperty -Path "$Reg" -Name PATH).Path

$shortpaths

Set-ItemProperty -Path "$Reg" -Name PATH –Value $shortpaths


Umeed4u


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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