I have been trying to find a solution to this problem, I am creating a CSV from a larger File, selecting specific columns, and I have received great support from here, and that task is being done, but My CSV file contains values that i would like to replace, for example, the column 'User Name', I only would like to keep 1 user, meaning delete everything after the "," and I got a Regex that looks like
(,.*$)|(not applicable)|(sscope)
That's what i would like to replace with empty string, but I am unable to get that to work, it deletes everything sometimes.
The value in the User Name column looks like this
User Name
B2 cell : not applicable
B3 cell : sscope, sscope
B4 cell : sscope
B5 cell : sscope, sscope, hernhng002, coanbvf001, clacbff01, polsbvcw04, taylor38, milthy12, hic6yth31, carruhgy58, grabngh09, starytht37, milytht937
B6 cell : tamyhg4647adm
B7 cell : moreduj4664
Question 2: How do I add a column that is coming from a different CSV file based on the common key (name column in both) but only 1 file has the memory column and i want to add it to the fist file. Thanks
. D:\Data\BF_Scripts\Write-Log.ps1
$filePath = "D:\Data\Input\bigFixDataNew.csv"
#$filePath = "D:\Data\Input\BF_Test_Dec2019.csv"
$System = "D:\Data\Output\System.csv"
$desiredColumnsSystem = @{ expression = {$_.'Internal Computer ID'}; label = 'RESOURCEID' },
@{ expression = {$_.'Computer Name'}; label = 'NAME'},
@{ expression = {$_.'DNS Name'}; label = 'DOMAIN'},
@{ expression = {$_.'DNS Name'}; label = 'USER_DOMAIN'},
@{ expression = {$_.'User Name'}; label = 'USER_NAME'}
$Regex = '(,.*$)|(, sscope)|(sscope)'
Try {
Write-Log -Message 'Starting Creation of System CSV...'
Import-Csv $filePath | Select-Object $desiredColumnsSystem | Sort RESOURCEID -Unique |
Export-Csv -Path $System –NoTypeInformation
$content = Get-Content $System
$content | ForEach-Object {$_ -replace $Regex,''} | Set-Content $System
$size = ((Get-Item $system).length/1KB)
$lastTouchedDate = (Get-Item $system).LastWriteTime
Write-Log -Message "Created the System CSV Successfully !! The size of $system is $size KB and the last write time was $lastTouchedDate"
}
catch
{
Write-Log -Message $_.Exception.Message
}