Home > Back-end >  Remove characters in csv file powershell
Remove characters in csv file powershell

Time:12-01

enter image description hereI'm running a ps1 script as gpo in all the computers from the domain, this script will bring certain details of each computer such as hostname, manufacturer, OS, etc and save it to a csv file.

I'm having an issue since the script runs just fine, however for some reason there are like empty spaces between some lines.

For example:

ThinkCentre M73;"PC-L314-PER03";"LENOVO";"Microsoft Windows 10 Pro" ;;; To be filled by O.E.M.;"PC-L312-PER02";"LENOVO";"Microsoft Windows 10 Pro" ThinkCentre M700;"PC-L111-GES";"LENOVO";"Microsoft Windows 10 Pro" ;;; ThinkCentre M70q;"PC-L367-REC01";"LENOVO";"Microsoft Windows 10 Pro"

; it's the delimiter I have set. Since I have already gathered the information needed, I'm importing the CSV to PS so that I can clean this empty spaces and export it back to a CSV file so that I can upload this to A DB.

Any ideas how to get rid of the spaces between lines?

Any help would be much appreciated.

Thanks in advance.

I've been googling for a solution but haven't been able to find something that fits my case.

CodePudding user response:

As per my comment. Here's what I mean.

Clear-Host
@'
ThinkCentre M73;"PC-L314-PER03";"LENOVO";"Microsoft Windows 10 Pro" 
;;; 
To be filled by O.E.M.;"PC-L312-PER02";"LENOVO";"Microsoft Windows 10 Pro" 
ThinkCentre M700;"PC-L111-GES";"LENOVO";"Microsoft Windows 10 Pro" 
;;; 
ThinkCentre M70q;"PC-L367-REC01";"LENOVO";"Microsoft Windows 10 Pro"
'@ -replace '; \s '
# Results
<#
ThinkCentre M73;"PC-L314-PER03";"LENOVO";"Microsoft Windows 10 Pro" 
To be filled by O.E.M.;"PC-L312-PER02";"LENOVO";"Microsoft Windows 10 Pro" 
ThinkCentre M700;"PC-L111-GES";"LENOVO";"Microsoft Windows 10 Pro" 
ThinkCentre M70q;"PC-L367-REC01";"LENOVO";"Microsoft Windows 10 Pro"
#>
  • Related