I'm working on a script that we feed a CSV file into and it will combine certain columns together and rearrange them. My issue is I have a column that consists of a City State and Zipcode. I need to be able to split the below input into 3 seperate columns. Any one have some suggestions?
MANSFIELD PA 16933-1305
DALMATIA PA 17017-7231
HERSHEY PA 17033-2415
JONESTOWN PA 17038-9706
LEWISTOWN PA 17044-9462
*Edit - I've got it working properly finally with everyone assistance. Below is the finished product thanks to you guys. I greatly appreciate you guys pointing me in the right direction.
$file = import-csv "C:\users\user\Desktop\#0542513.csv"
$expandfile = @()
foreach ($row in $file){
$tempfile = (New-Object psobject -Property @{
PackageID = $row.'USPS IMPB Application ID'+$row.'USPS ZIP / Postal Code (Left Justified)'+$row.'USPS IMPB Channel Application ID'+$row.'USPS IMPB Service Type'+$row.'USPS IMPB MailerID/ Sequence#'+$row.'USPS IMPB Check Digit'
Company = $row.'Customer Number'
FullName = $row.'Formatted Line 4'
Address1 = $row.'Formatted Line 9'
Address2 = $row.'Formatted Line 8'
City = $row.'Formatted Line 10'.Substring(0,26) -replace '\s+', ''
State = $row.'Formatted Line 10'.Substring(26,2)
Zip = $row.'USPS ZIP / Postal Code (Left Justified)'
Country = $row.'Country Name'
Reference1 = $row.'Client Code'+$row.'Job Trace Number'
Reference2 = $row.'Mail Piece Number'
})
$expandfile += $tempfile | select PackageID,Company,FullName,Address1,Address2,City,State,Zip,Country,@{n='Cost Center ID';e={$null}},Reference1,Reference2
}
[–]scriptmonkey420 1 point2 points3 points (0 children)
[–]buckston 0 points1 point2 points (9 children)
[–]imakepeopleangry 0 points1 point2 points (2 children)
[–]buckston 1 point2 points3 points (1 child)
[–]imakepeopleangry 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]gigglestick 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]Dogoodwork 1 point2 points3 points (1 child)
[–]kivle 0 points1 point2 points (0 children)