export data from pssession

Welcome Forums General PowerShell Q&A export data from pssession

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #63941

    Topics: 5
    Replies: 6
    Points: 0
    Rank: Member

    The scenario is I have to read an XML file on about 60 PC's on our network. I need to get two pieces of data out of that xml file. Last I need to put that data into a network location from that possession.

    My problem is I am always getting this error trying to write to the network location
    out-File : Access to the path '\\server\share\folder\file.txt' is denied.
    My code is as follows
    $s = New-PSSession -ComputerName pcname -Credential domain\userid

    Enter-PSSession -Session $s
    New-PSDrive -Name Z -PSProvider FileSystem -Root '\\server\share\folder'

    [XML]$xml = Get-Content –Path "C:\program files (x86)\appname\config.xml"

    $data = ($xml.Settings | Select-Object -Property tag1, tag2 |
    Format-Table -HideTableHeaders | Out-String -Width 19)

    Here is the line that gets me scratching my head
    $data.Trim() |Out-file z:\stationid.txt -Append

  • #63944

    Topics: 1
    Replies: 1267
    Points: 1,395
    Helping Hand
    Rank: Community Hero

    You don't need a pssession to read an xml file on another computer

    [XML]$xml = Get-Content –Path "\\Server\C$\program files (x86)\appname\config.xml"

    And you don't need to map a drive to write a file to a share

    $data.Trim() | Out-file \\server\share\folder\stationid.txt -Append

    and probably it would be faster to collect all the data you need first and then write it at once to the output file.
    And if you get an "Access denied" probably you don't have access. 😉

  • #63965

    Topics: 5
    Replies: 6
    Points: 0
    Rank: Member


    Thank you simplifying the script helped. I am moving forward again. I forgot to use the KISS principle Keep It Simple Stupid


The topic ‘export data from pssession’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort