Deleting spaces in variable
by BassieBas at 2013-03-04 01:14:54
I have made a powershell script to create a new client with multiple users in our environment.
That is working just fine, but the only thing is that i need to delete te spaces in a variable.
The name of the company (Micro Soft) is used for the OU, Group and directory name.
The only thing is that i need that companyname (Micro Soft) to be without spaces (MicroSoft).
How can i manage to do this? I work with Powershell ISE on a Windows Server 2008R2 environment.
In forward many thanks.
by mjolinor at 2013-03-04 03:26:12
The simplest way to remove the spaces from a string is with the .replace() method:
$var = 'Micro Soft'
$var = $var.replace(' ','')
by compugab at 2013-03-04 03:37:48
You could also use a more "PowerShell Way" with -replace like this :
$a = "a b c d"
$a -replace " ", ""
by BassieBas at 2013-03-04 03:42:24
That worked, thank you so much for the fast reply!
You must be logged in to reply to this topic.