There are some commands I want to run in bulk. the syntax requires the commands to be built with no space between the first two columns.
I have everything working except this one space that's created between command and serial number.
Here's what I have:
$command = "My command I need to run:"
#prompt user for Destination OrgUnit
$OrgUnit = Read-Host "Paste the destination orgUnit here:"
#grab csv of serial numbers
Import-CSV -Path C:\CSV\serials.csv -Header serialnumber | ForEach-Object {
[PSCustomObject] @{
"myCommand" = $command
"Serial" = $_.serialnumber
"OrgUnit" = $OrgUnit
}
} | Out-File C:\CSV\Command.txt
Here's what's I'm getting in my .txt file
myCommand Serial OrgUnit
--------- ------ -------
My command I need to run: serialnumber TestOrgUnit
My command I need to run: 5062TBH TestOrgUnit
My command I need to run: 5032TZS TestOrgUnit
My command I need to run: 4362BTD TestOrgUnit
My command I need to run: 3256FDR TestOrgUnit
My command I need to run: 6087WSD TestOrgUnit
My command I need to run: 8761GWD TestOrgUnit
My command I need to run: 8876FGT TestOrgUnit
My command I need to run: 5062TBF TestOrgUnit
My command I need to run: 5062Tpl TestOrgUnit
My command I need to run: 5062HGD TestOrgUnit
Which is great. Only problem is I need to remove the space between "My command I need to run:" and "serialnumber" and only that space.
The desired output should be
myCommand Serial OrgUnit
--------- ------ -------
My command I need to run:serialnumber TestOrgUnit
My command I need to run:5062TBH TestOrgUnit
My command I need to run:5032TZS TestOrgUnit
EDIT: Thank you Ann L !
I went with
(Get-Content C:\CSV\Command.txt).replace(": ", ':') | Set-Content C:\CSV\Command.txt