Dear Steve Hanna,
The behavior you're observing—where the path appears twice like this:
Code
C:\scripts\pospay\Archive\2025\10\30
C:\scripts\pospay\Archive\2025\10\30
—likely results from a combination of how PowerShell handles output and how the function is being called.
In your script:
powershell
$LogDirectory = Get-Logfile-Directory -RootDirectory $ArchiveDirectory
write-host $logdirectory
There are two key points to consider:
- Implicit Output from Function Call PowerShell automatically writes the return value of a function to the output stream if it's not being suppressed. So when you assign the result to
$LogDirectory, the function still outputs the return value unless redirected or explicitly suppressed. - Explicit Output via
Write-HostYou're also printing the same variable again withwrite-host $logdirectory. Note that PowerShell is case-insensitive, so$logdirectoryand$LogDirectoryrefer to the same variable.
To avoid duplicate output, you can suppress the implicit output by redirecting it or simply rely on one output method. For example:
powershell
$null = Get-Logfile-Directory -RootDirectory $ArchiveDirectory
Write-Host "Log directory: $LogDirectory"
Or, if you want to capture and display the result:
powershell
$LogDirectory = Get-Logfile-Directory -RootDirectory $ArchiveDirectory
Write-Host "Log directory: $LogDirectory"
This will ensure the path is printed only once.
For logging or scripting purposes, consider using Write-Output or Out-File instead of Write-Host, as it provides more flexibility for redirection and automation.
If this guidance proves helpful, feel free to click “Accept Answer” so we know we’re heading in the right direction 😊. And of course, I’m here if you need further clarification or support.
T&B,
Domic.