-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
I have an issue similar to what was reported here: #10136 and #5868 (possibly others)
This feels/looks similar to a Double Hop problem, however It's intermittent and not specifically related.
Scenario
When I connect from one machine to the second using WSMAN, I am (intermittently) unable to map a drive to a 2nd hop file share, even though I am providing fresh credentials.
New-PSDrive fails with the error:
Exception:
System.ComponentModel.Win32Exception (1312): A specified logon session does not exist. It may already have been terminated.
FullyQualifiedError:
CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
The strange things is that you can generally connect the first time, then never the 2nd time. However if you set the new-psdrive -scope local then you can connect the 2nd time and there after.
However if you connect the first time without -scope local and then you set -scope local the 2nd time, then you cannot connect. However if you wait a certain amount of time then you can connect again.
removing the pssession and creating that does not help. rebooting the 2nd machine and then reconnecting doesn't work, rebooting the client machine doesn't work.
Here is the code for the repro
$PS7ComputerName = 'AZC1ADFS1DC01'
$SAName = 'stagecus1'
if (!($Cred)){$cred = get-credential $SAName}
$root = "\\$SAName.file.core.windows.net\source"
# Test against PC 7 preview 6 . . works fine only the first time when not using new-psdrive -scope local.
$psSessionEndPoint7 = "PowerShell.7-preview"
$s7 = New-PSSession -ComputerName $PS7ComputerName -ErrorAction SilentlyContinue -ConfigurationName $psSessionEndPoint7 #-SessionOption $pso
$s7
icm -Session $s7 -ScriptBlock {
$cred = $using:cred
$drive = 'P'
write-warning "hostname: $(hostname)"
write-warning "PSVersion: $($PSVersionTable.PSVersion.tostring())"
if (-not(get-psdrive -name $drive -ErrorAction SilentlyContinue))
{
Try {
New-PSDrive -name $drive -Root $using:root -PSProvider FileSystem -Credential $using:cred -Persist -EA Stop -Scope local | ft -auto
dir "${drive}:\" -ErrorAction SilentlyContinue
}
Catch {
$_ | select *
#$_.exception
#$_.exception.stacktrace
}
finally {
get-psdrive -name $drive -ea 0 | remove-psdrive
}
}
}
Expected behavior - map the drive and list the files
WARNING: hostname: azc1adfs1dc01
WARNING: PSVersion: 7.0.0-preview.6
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
P 7.17 5112.83 FileSystem \\stagecus1.file.core.windows.net\source
Directory: P:\
Mode LastWriteTime Length Name PSComputerName
---- ------------- ------ ---- --------------
d---- 9/5/2019 2:15 PM AADAppProxy AZC1ADFS1DC01
d---- 9/5/2019 2:15 PM ADConnect AZC1ADFS1DC01
d---- 9/5/2019 2:15 PM AZFileSync AZC1ADFS1DC01
Actual behavior
Once you remove the scope
E.g.
New-PSDrive -name $drive -Root $using:root -PSProvider FileSystem -Credential $using:cred -Persist -EA Stop #-Scope localIt will map the drive only 1 time, then it will fail again.
- adding the scope again does not fix the issue, unless you wait. then try again later.
WARNING: hostname: azc1adfs1dc01
WARNING: PSVersion: 7.0.0-preview.6
PSMessageDetails :
Exception : System.ComponentModel.Win32Exception (1312): A specified logon session does not exist. It may already have been terminated.
TargetObject : P
CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 11
PipelineIterationInfo : {}
PSComputerName : AZC1ADFS1DC01
RunspaceId : 34e26d9a-f019-4d6c-bd25-15380f1c1629
Environment data
$PSVersionTable
Name Value
---- -----
PSVersion 7.0.0-preview.6
PSEdition Core
GitCommitId 7.0.0-preview.6
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0