none
Powershell - Remote CSV File RRS feed

  • Question

  • Trying to load a CSV file sitting on a remote PC into a datagridview. Getting access denied, I need to provide credentials somehow but can't seem to find the best way to do it. So far I have something like this...

    $rows = Import-Csv -Path "\\servername\e$\path\file.csv" -Header Header1,Header2
    $table = ConvertTo-DataTable -InputObject $rows
    Update-DataGridView -DataGridView $datagridview1 -Item $table

    This fails with access denied. Looking for a way to access this file on the remote server and load it into my datagrid.

    • Moved by Bill_Stewart Wednesday, September 4, 2019 6:01 PM This is not "train me in basic Windows security" forum
    Friday, February 22, 2019 3:01 PM

All replies

  • Use Get-Credential?

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-credential?view=powershell-6

    Friday, February 22, 2019 3:11 PM
  • I'm familiar with Get-Credential, passing it to the commands is what I'm trying to figure out. I've tried this....

    $creds = Get-Credential
    $session = New-PSSession -ComputerName "servername" -Credential $creds
    Enter-PSSession $session

    $rows = Import-Csv -Path "\\servername\e$\path\file.csv" -Header Header1,Header2
    $table = ConvertTo-DataTable -InputObject $rows
    Update-DataGridView -DataGridView $datagridview1 -Item $table


    Exit-PSSession
    Remove-PSSession $session

    Doesn't seem to be correct though. Trying to figure out how to use it here.

    Friday, February 22, 2019 3:50 PM
  • Doesn't seem to be correct though. Trying to figure out how to use it here.

    You cannot use a remote session in a script.  You can only use Invoke-Command" . "Enter-PsSession" is only use at a command prompt for interactive remote sessions.

    help invoke-command -online

    \_(ツ)_/


    • Edited by jrv Friday, February 22, 2019 9:11 PM
    Friday, February 22, 2019 9:09 PM
  • Don't use the e$ share. That is a built in share and requires an administrator account to access. Create a user share at e:\path and grant access to the account that is executing powershell.exe.  
    Saturday, February 23, 2019 1:49 PM