Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Write-log {
- [CmdletBinding()]
- param(
- [Parameter(Mandatory = $true)]
- [string]$Path,
- [Parameter(Mandatory = $true)]
- [string]$Message,
- [Parameter(Mandatory = $true)]
- [string]$Component,
- [Parameter(Mandatory = $true)]
- [ValidateSet("Info","Warning","Error")]
- [string]$Type
- )
- switch ($Type) {
- "Info" { [int]$Type = 1 }
- "Warning" { [int]$Type = 2 }
- "Error" { [int]$Type = 3 }
- }
- # Create a log entry
- $Content = "<![LOG[$Message]LOG]!>" + `
- "<time=`"$(Get-Date -Format "HH:mm:ss.ffffff")`" " + `
- "date=`"$(Get-Date -Format "M-d-yyyy")`" " + `
- "component=`"$Component`" " + `
- "context=`"$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)`" " + `
- "type=`"$Type`" " + `
- "thread=`"$([Threading.Thread]::CurrentThread.ManagedThreadId)`" " + `
- "file=`"`">"
- # Write the line to the log file
- Add-Content -Path $Path -Value $Content
- }
- #Global Variables
- $Version = "v1.0"
- $Date = Get-Date -Format yyyyMMdd
- $log = "C:\temp\manipulate.log"
- $LogLevel = "None"
- $oldText = 'OldText'
- $newText = 'NewText'
- $Source= 'C:\Temp\old'
- $Destination = 'C:\Temp\New'
- $Directory=get-childitem -name $Source
- while ($Directory -ne 'NoEnd'){
- If ($Directory) {
- foreach ($file in $Directory){
- $content = (Get-Content $Source\$file) -replace $oldText,$newText
- $content |Set-Content $Destination\$file -Force -Confirm:$false
- Write-Log -Path $log -Message "Replaced $oldText with $newText in File: $file" -Component Script-Remove -Type Info
- Remove-Item -Path $Source\$file -Recurse -Force -Confirm:$false
- Write-Log -Path $log -Message "File: $file - removed..." -Component Script-Remove -Type Info
- Write-Log -Path $log -Message "---------------------------------------" -Component Script-Wait -Type Info
- }
- $Directory=get-childitem -name $Source
- }
- if (!$Directory){
- Write-Log -Path $log -Message "No New Files found, waiting for 60 seconds" -Component Script-Wait -Type Info
- Write-Log -Path $log -Message "---------------------------------------" -Component Script-Wait -Type Info
- sleep 60
- $Directory=get-childitem -name $Source
- }
- }
Add Comment
Please, Sign In to add comment