FSCorrupted

PS Watcher

Jun 17th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Write-log {
  2.  
  3.     [CmdletBinding()]
  4.     param(
  5.         [Parameter(Mandatory = $true)]
  6.         [string]$Path,
  7.  
  8.         [Parameter(Mandatory = $true)]
  9.         [string]$Message,
  10.  
  11.         [Parameter(Mandatory = $true)]
  12.         [string]$Component,
  13.  
  14.         [Parameter(Mandatory = $true)]
  15.         [ValidateSet("Info","Warning","Error")]
  16.         [string]$Type
  17.     )
  18.  
  19.     switch ($Type) {
  20.         "Info" { [int]$Type = 1 }
  21.         "Warning" { [int]$Type = 2 }
  22.         "Error" { [int]$Type = 3 }
  23.     }
  24.  
  25.     # Create a log entry
  26.     $Content = "<![LOG[$Message]LOG]!>" + `
  27.     "<time=`"$(Get-Date -Format "HH:mm:ss.ffffff")`" " + `
  28.     "date=`"$(Get-Date -Format "M-d-yyyy")`" " + `
  29.     "component=`"$Component`" " + `
  30.     "context=`"$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)`" " + `
  31.     "type=`"$Type`" " + `
  32.     "thread=`"$([Threading.Thread]::CurrentThread.ManagedThreadId)`" " + `
  33.     "file=`"`">"
  34.  
  35.     # Write the line to the log file
  36.     Add-Content -Path $Path -Value $Content
  37. }
  38.  
  39. #Global Variables
  40. $Version = "v1.0"
  41. $Date = Get-Date -Format yyyyMMdd
  42. $log = "C:\temp\manipulate.log"
  43. $LogLevel = "None"
  44.  
  45. $oldText = 'OldText'
  46. $newText = 'NewText'
  47.  
  48. $Source= 'C:\Temp\old'
  49. $Destination = 'C:\Temp\New'
  50.  
  51. $Directory=get-childitem -name $Source
  52.  
  53. while ($Directory -ne 'NoEnd'){
  54.     If ($Directory) {
  55.         foreach ($file in $Directory){
  56.             $content = (Get-Content $Source\$file) -replace $oldText,$newText
  57.             $content |Set-Content $Destination\$file -Force -Confirm:$false
  58.             Write-Log -Path $log -Message "Replaced $oldText with $newText in File: $file" -Component Script-Remove -Type Info
  59.             Remove-Item -Path $Source\$file -Recurse -Force -Confirm:$false
  60.             Write-Log -Path $log -Message "File: $file - removed..." -Component Script-Remove -Type Info
  61.             Write-Log -Path $log -Message "---------------------------------------" -Component Script-Wait -Type Info
  62.         }
  63.         $Directory=get-childitem -name $Source
  64.     }
  65.     if (!$Directory){
  66.         Write-Log -Path $log -Message "No New Files found, waiting for 60 seconds" -Component Script-Wait -Type Info
  67.         Write-Log -Path $log -Message "---------------------------------------" -Component Script-Wait -Type Info
  68.         sleep 60
  69.         $Directory=get-childitem -name $Source
  70.     }
  71.     }
Add Comment
Please, Sign In to add comment