Advertisement
yadav2152003s

Batch Processor

Jun 16th, 2021
1,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $sourcedir = "C:\Folder1\"
  2. $resultsdir = "C:\Folder1\"
  3.  
  4. <# I copy the content of the tag <link rel="canonical"  in the tag "OG:URL" and in the tag  "@ID":             #> `
  5.  
  6. Get-ChildItem -Path $sourcedir -Filter *.html | ForEach-Object {
  7.    $content = Get-Content -Path $_.FullName -Raw
  8.    $replaceValue = (Select-String -InputObject $content -Pattern '(?<=<link rel="canonical" href=").+(?=" />)').Matches.Value
  9.    $content = $content -replace '(?<=<meta property="og:url" content=").+(?="/>)',$replaceValue
  10.     Set-Content -Path $resultsdir\$($_.name) $content
  11.    $content = $content -replace '(?<="@id": ").+(?=")',$replaceValue
  12.     Set-Content -Path $resultsdir\$($_.name) $content
  13.    
  14. <# I copy the content of the tag <title>  in the tags ABSTRACT, SUBJECT, OG:TITLE, HEADLINE, KEYWORDS            #> `
  15.    
  16.   $replaceValue = (Select-String -InputObject $content -Pattern '(?<=<title>).+(?=</title>)').Matches.Value
  17.   $content = $content -replace '(?<=<meta name="abstract" content=").+(?="/>)',$replaceValue
  18.    Set-Content -Path $resultsdir\$($_.name) $content
  19.   $content = $content -replace '(?<=<meta name="Subject" content=").+(?="/>)',$replaceValue
  20.    Set-Content -Path $resultsdir\$($_.name) $content
  21.   $content = $content -replace '(?<=<meta property="og:title" content=").+(?=" />)',$replaceValue
  22.    Set-Content -Path $resultsdir\$($_.name) $content
  23.   $content = $content -replace '(?<="headline": ").+(?=",)',$replaceValue
  24.    Set-Content -Path $resultsdir\$($_.name) $content
  25.   $content = $content -replace '(?<="keywords": ").+(?=",)',$replaceValue
  26.    Set-Content -Path $resultsdir\$($_.name) $content
  27.    
  28. <# I copy the content of the tag <meta name="description"  in the tags "OG:DESCRIPTION" and in the tag "description": "        #> `
  29.    
  30.    $replaceValue = (Select-String -InputObject $content -Pattern '(?<=<meta name="description" content=").+(?="/>)').Matches.Value
  31.    $content = $content -replace '(?<=<meta property="og:description" content=").+(?="/>)',$replaceValue
  32.     Set-Content -Path $resultsdir\$($_.name) $content
  33.     $content = $content -replace '(?<="description": ").+(?=",)',$replaceValue
  34.     Set-Content -Path $resultsdir\$($_.name) $content  
  35.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement