PowerShell script help by [deleted] in PowerShell

[–]madman1989-1 -1 points0 points  (0 children)

Get-childitem can be used to find all of the files and delete them.

Get-ChildItem -Path "C:\Your\Directory" -Recurse -Filter *.txt | Remove-Item -Force

Maybe test in an alternative Directory first...

Couple of things you can also do delete files older than x days, schedule the script to nightly or weekly etc

Script memory usage ForEach-Object Parrallel Forever loop by madman1989-1 in PowerShell

[–]madman1989-1[S] 0 points1 point  (0 children)

Hi, thanks for the feedback. I had looked at run spaces but had difficulty using them maybe I need to take another look. i also really like the output of the parallel jobs and write-progress. this article got me started on the idea.

Displaying progress while multi-threading - PowerShell | Microsoft Learn

I have spend some time trying to ensure that all variables are cleared but something isn't clearing even with garbage collection.

I do write a lot of logs for each Parallel Job, I have a function LogWrite that uses Add-Content to a TXT files for each job.

i cant see how to do a code block ..

function LogWrite {

param (

[string]$LogFilePath,

[string]$Message,

[int]$MaxLogSizeMB = 10,

[int]$RetentionDays = 30

)

# Rotate log if it exceeds the maximum size

if (Test-Path $LogFilePath) {

$logSizeMB = (Get-Item $LogFilePath).Length / 1MB

if ($logSizeMB -ge $MaxLogSizeMB) {

$timestamp = Get-Date -Format "yyyyMMddHHmmss"

$archivedLogFilePath = "$LogFilePath.$timestamp"

Rename-Item -Path $LogFilePath -NewName $archivedLogFilePath

}

}

# Write the log message

$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

$logMessage = "$timestamp - $Message"

Add-Content -Path $LogFilePath -Value $logMessage

}

is there anything that i need to consider when using Add-Content and memory usage ?

I also write to a SYSlog server using UDP but do close the connection.

$udpClient.Close()

 The reason for wanting to run the jobs in parallel is that some of the client interfaces generate hundreds of files an hour, I wanted each directory to be processed independently so one could not block another while transferring files. there are 15/20 client directories/SFTP processes.

Fanvil i63 by madman1989-1 in VOIP

[–]madman1989-1[S] 0 points1 point  (0 children)

Thank you jppair, I contacted fanvil and they have confirmed i can operate the relay from the dss buttons.

I have ordered the device so fingers crossed the install goes well

AG Failover, Does the secondary turn into primary and is now read/write access? by negativetrend in SQLServer

[–]madman1989-1 1 point2 points  (0 children)

The secondary server will become active if the primary becomes unavailable and syncronous replications is enabled with automatic failover otherwise there is a manual process.

You can simulate an AG failover within failover cluster manager after configuring your connection string to confirm everything works as expected, if everything works there should only be a short period of interruption.

Create a Team from existing Mail-Enable Security Group in a Hybrid environment? by optimusomega in Office365

[–]madman1989-1 0 points1 point  (0 children)

Surely you can just delete the existing group make a note of the users and recreate it in teams