0

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
crustmc
  • 13
  • 5
  • Would it be possible to run your output file through some kind of find-replace filter that could convert ": " to ":"? – Ann L. Jul 29 '22 at 21:40
  • Actually, yes: https://stackoverflow.com/a/17144445/490374 – Ann L. Jul 29 '22 at 21:42
  • Is it as simple as combining those two columns into one within your object? `"myCommand" = $command + $_.serialnumber` – DBADon Jul 31 '22 at 22:07

0 Answers0