Replace CRLF with LF to Rescue My Packages –Powershell



Get-ChildItem -Path d:\mypackages\* -recurse |  Select-String -Pattern "myString" | Out-File c:\temp\filesContainsMyString.txt  

get-childitem d:\mypackages\*.dtsx -recurse |  
 select -expand fullname |
  foreach {
 $mycontent = Get-Content $_

if ($mycontent  -like '*myString*' )
{
(Get-Content $_) -replace "myString", "myOtherString"  | Set-Content $_}
}

#######################################################

get-childitem d:\mypackages\*.dtsx -recurse | 
 select -expand fullname |
foreach { 
 $mycontent = Get-Content $_

if ($mycontent  -like '*myOtherString*') 
{
 $text1 = [IO.File]::ReadAllText($_) -replace "`r`n", "`n"  
[IO.File]::WriteAllText($_, $text1)

}
}

Get-ChildItem -Path d:\mypackages\* -recurse |  Select-String -Pattern "myOtherString" | Out-File c:\temp\filesContainsMyOtherString.txt  

 


########## use encoding switch for Set-Content should be better option

##### http://stackoverflow.com/questions/28123279/powershell-set-content-seems-to-corrupt-my-ssis-dtsx-files
#####       Set-Content $_ -Enc Utf8    

get-childitem d:\mypackages\*.dtsx -recurse |  
 select -expand fullname |
  foreach {
 $mycontent = Get-Content $_

if ($mycontent  -like '*myString*' )
{
(Get-Content $_) -replace "myString", "myOtherString"  | Set-Content $_ -Enc Utf8}
}





 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s