V4.1.0 - Change log's location

In PSADT v4.1, how can i change all log's location, in real time?
in 3.10.2, i add somethink like this
$customLogPath = $LogAuto = Join-Path -Path "$env:SystemRoot\Temp\Logs" -ChildPath "LogFolder"
If ($Variable) {
$configToolkitLogDir = $customLogPath
$configMSILogDir = $customLogPath
}

With this, i can redirection the logs to another folder than the default, but i'm struggling with v4.1

Why not do it in \Config\config.psd1

        # Log path used for Toolkit logging.
        LogPath = '$env:SystemRoot\Temp\Logs'

and the MSI log path will follow PSADT's

It doesn't need to be dynamic, right?

That's the problem i want it dynamic.
If a variable is true, it's on a location , if false is going to another place.

It's too bad the path isn't inside an environment variable. Then you could have used it directly in the Config.psd1

The best time to set the log file location is BEFORE the session opens.
I know you can change the NAME of the log file but I've never tried to set the log file LOCATION.

Near the top of the FrontScript (aka Invoke-AppDeployToolkit.ps1) where $adtSession is defined, try something this:

$adtSession = @{
    # App variables.
    AppVendor = 'Microsloth'
...
...
}
#Set Logging Location:
If ($Something -eq $true)
	$adtSession.LogPath = "C:\logpath1"
} Else {
	$adtSession.LogPath = "C:\logpath2"
}

let me try that..
I will post feedback

Edit: @That-Annoying-Guy , did not worked, log still created on default location ( defined in config.psd1)

You might be able to move that block of code to right after the session opens:

    # Open a new deployment session, replacing $adtSession with a DeploymentSession.
    $iadtParams = Get-ADTBoundParametersAndDefaultValues -Invocation $MyInvocation
    $adtSession = Remove-ADTHashtableNullOrEmptyValues -Hashtable $adtSession
    $adtSession = Open-ADTSession @adtSession @iadtParams -PassThru

	#Set Logging Location:
	If ($Something -eq $true)
		$adtSession.LogPath = "C:\logpath1"
	} Else {
		$adtSession.LogPath = "C:\logpath2"
	}
}
catch
{
    $Host.UI.WriteErrorLine((Out-String -InputObject $_ -Width ([System.Int32]::MaxValue)))
    exit 60008
}

But I expect weird things like the log file to be split in two.

  • Half in as per config.psd1
  • Half in the new location

Mitch might have ideas...

I think that already tried that one, and get " logpath property is read only".
But tomorow i will give it another shot.

1 Like

Find the below lines in your Invoke-AppDeployToolkit.ps1 script:

    # Open a new deployment session, replacing $adtSession with a DeploymentSession.
    $iadtParams = Get-ADTBoundParametersAndDefaultValues -Invocation $MyInvocation
    $adtSession = Remove-ADTHashtableNullOrEmptyValues -Hashtable $adtSession
    $adtSession = Open-ADTSession @adtSession @iadtParams -PassThru

and change them to:

    # Open a new deployment session, replacing $adtSession with a DeploymentSession.
    Initialize-ADTModule -ScriptDirectory $PSScriptRoot
    (Get-ADTConfig).Toolkit.LogPath = 'C:\Some\Other\Log\Path'
    $iadtParams = Get-ADTBoundParametersAndDefaultValues -Invocation $MyInvocation
    $adtSession = Remove-ADTHashtableNullOrEmptyValues -Hashtable $adtSession
    $adtSession = Open-ADTSession @adtSession @iadtParams -PassThru
1 Like

This is it @mjr4077au ! thank you very much for your help @That-Annoying-Guy and @mjr4077au !

1 Like

Got another issue, when i run the Invoke-AppDeployToolkit.exe, passing a custom parameter
([Parameter(Mandatory = $false)]
[switch]$Log= $false),
and using the code that @mjr4077au sent, i get this on the debug window

(Open-ADTSession : Cannot convert the object of type 'System.Management.Automation.PSObject' to type 'System.String'.
At C:\Test\Invoke-AppDeployToolkit.ps1:324 char:19
+     $adtSession = Open-ADTSession @adtSession @iadtParams -PassThru
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (60008:Int32) [Open-ADTSession], InvalidCastException
    + FullyQualifiedErrorId : System.InvalidCastException,Open-ADTSession

Can you open a PowerShell window, import the module (the PSAppDeployToolkit folder), run & 'C:\Path\To\Invoke-AppDeployToolkit.ps1', then run Resolve-ADTErrorRecord -ErrorRecord $Error[0]. There's not enough info without a resolved error output.

EDIT: i fixed it, the problem was the variable that was getting the log path.
Can close it, and thank you for your availability, you guys @mjr4077au and @That-Annoying-Guy

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.