Help with unc path

Hi there.
I am trying to get the unc path from servers in file in this script to work but I can’t for some reson. The param $serverName is empty. Some help please.

$serverFiles = @(
    "C:\Scripts\Antura\Servers\allServersGFTest.txt"
)

$servers = @()

foreach ($file in $serverFiles) {
    $servers += Import-Csv -Path $file
}

foreach ($serverInfo in $servers) {
    $option    = New-PSSessionOption -IncludePortInSPN
    $pssession = New-PSSession -ComputerName $serverInfo.Name -SessionOption $option

    $scriptPath = Invoke-Command -Session $pssession -ScriptBlock {
        param (
            $serverName
        )

        $uncPath = "\\$serverName\c`$\Scripts\DailyMonitor\*.ps1"
        $scriptPath = Get-ChildItem $uncPath -Recurse -Depth 0 -File |
                      Where-Object { $_.Name -notlike '*Copy*' -and $_.Name -notlike '*original*' } |
                      Select-Object -First 1

        if ($scriptPath) {
            $scriptPath.FullName
        }
    } -ArgumentList $serverInfo.Name

    if ($scriptPath) {
        # Start PowerShell script
        Invoke-Expression -Command $scriptPath
    } else {
        Write-Host "No PowerShell script (*.ps1) found (excluding those with 'Copy') in the specified path on $($serverInfo.Name)."
    }

    # Remove the session inside the loop
    Remove-PSSession $pssession
}

I manage to solved the problem my self.
I am closing this.

You may share your solution with the world to help others looking for a solution for the same or a similar problem. :wink: :+1:t3: :love_you_gesture:t3:

I changed after $scriptPath to this instead.

        if ($scriptPath) {
            $scriptPath.FullName
        }

        Invoke-Expression -Command $ScriptPath
    } -ArgumentList $serverInfo.Name

```As one can se is that I get rid of the last if/else and that did it.