Running from ISE as non admin accountand passing admin creds. This code will work with get-childitem but not the start-process. First run shows psdrive working, dir listing, whoami (is the admin account). If I run same code again, it will fail to map a drive, Why?
3rd run the start-process fails, I assume this isn’t a double hop issue since whoami is showing admin, and get-childitem shows me dir listing of UNC mapped drive. Why is start-process not working?
the argumentlist items work fine from CMD prompt. If I take -credentials out of start-process I am prompted but still get access denied so I feel creds are passing fine. How do I debug the start-process?
1st run works as expected
PS C:\Program Files (x86)\Microsoft Visual Studio\Installer> Invoke-Command -ComputerName $pc -Credential $credsWA -ScriptBlock {
#Map a virtual drive as .wa account and start-process uses the T drive to install. This gets around the double hop problem.
New-PSDrive -name t -PSProvider FileSystem -Root \\dmz\netinstall$\vs19_Ent -Credential $args[0]
#Start-Process -FilePath 't:\vs_setup' -ArgumentList "install --quiet --norestart --nocache --noweb --noupdateinstaller --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio" -Wait -Credential $args[0] -RedirectStandardError c:\temp\err.txt -RedirectStandardOutput c:\temp\out.txt -Verbose -PassThru
Get-ChildItem 't:\' -Filter *.exe
whoami
Remove-PSDrive -Name t
} -ArgumentList $credsWA
Name Used (GB) Free (GB) Provider Root CurrentLocation PSComputerName
---- --------- --------- -------- ---- --------------- --------------
t \\dmz\netinstall$\vs19_Ent minint-1.domain.local
LastWriteTime : 10/13/2021 9:03:09 AM
Length : 1468216
Name : vs_enterprise.exe
PSComputerName : minint-1.domain.local
LastWriteTime : 10/13/2021 9:03:09 AM
Length : 1468216
Name : vs_setup.exe
PSComputerName : minint-1.domain.local
domain\john.doe.wa
2nd run, same command, different results.
Access is denied
+ CategoryInfo : InvalidOperation: (t:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
+ PSComputerName : minint-1.domain.local
Cannot find drive. A drive with the name 't' does not exist.
+ CategoryInfo : ObjectNotFound: (t:String) [Get-ChildItem], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : minint-1.domain.local
domain\john.doe.wa
Cannot find drive. A drive with the name 't' does not exist.
+ CategoryInfo : ObjectNotFound: (t:String) [Remove-PSDrive], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand
+ PSComputerName : minint-1.domain.local
3rd run, removed get-child, added start-process. Drive works, install fails, i know I had this working
PS C:\Program Files (x86)\Microsoft Visual Studio\Installer> Invoke-Command -ComputerName $pc -Credential $credsWA -ScriptBlock {
#Map a virtual drive as .wa account and start-process uses the T drive to install. This gets around the double hop problem.
New-PSDrive -name t -PSProvider FileSystem -Root \\dmz\netinstall$\vs19_Ent -Credential $args[0]
Start-Process -FilePath 't:\vs_setup' -ArgumentList "install --quiet --norestart --nocache --noweb --noupdateinstaller --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio" -Wait -Credential $args[0] -RedirectStandardError c:\temp\err.txt -RedirectStandardOutput c:\temp\out.txt -Verbose -PassThru
#Get-ChildItem 't:\' -Filter *.exe
whoami
Remove-PSDrive -Name t
} -ArgumentList $credsWA
Name Used (GB) Free (GB) Provider Root CurrentLocation PSComputerName
---- --------- --------- -------- ---- --------------- --------------
t \\dmz\netinstall$\vs19_Ent minint-1.domain.local
This command cannot be run due to the error: Access is denied.
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
+ PSComputerName : minint-1.domain.local
domain\john.doe.wa