{"id":11325,"date":"2022-09-27T00:13:33","date_gmt":"2022-09-26T18:43:33","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/"},"modified":"2022-09-27T00:13:33","modified_gmt":"2022-09-26T18:43:33","slug":"solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/","title":{"rendered":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-63767861\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"63767861\" data-parentid=\"63755816\" data-score=\"1\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>In your previous questions your starting point was the <code>Get-DfsrMembership<\/code> cmdlet.  In this question you&#8217;ve switched to starting with <code>Get-ADComputer<\/code>.  What others have been trying to point out is properties returned from <code>Get-DfdMembership<\/code> aren&#8217;t available.  In particular <code>$_.ContentPath<\/code> isn&#8217;t available in this scenario.  Furthermore, <code>Get-ADComputer<\/code> returns a Name property not ComputerName.<\/p>\n<p>That said, your real question as described in your comments:<\/p>\n<blockquote>\n<p>however, the challenge is how to list the file names, size and<br \/>\nlocation in each respective servers and export as .CSV<\/p>\n<\/blockquote>\n<p>This is a question about patterns &amp; concepts.  You&#8217;re conflating a value that has meaning for the entire collection (the sum) with the individual elements of the collection.  The sum therefore can&#8217;t really be stored in the CSV. Imagine that each line of the CSV has the information from one of the 32 files, well then where on that line would you put the Sum? It has no meaning with respect to anything else on that line.<\/p>\n<p>Conceptually objects are self-contained.  It&#8217;s a conundrum to try to squeeze an unrelated property in like this. And, the flat-ish nature of CSV files makes it even more challenging.<\/p>\n<p>So how to deal with this?<\/p>\n<blockquote>\n<p>Note: Because of the <code>$_.ContentPath<\/code> problem I&#8217;ve hardcoded the path<br \/>\nbelow.  This is for demonstration not production!<\/p>\n<\/blockquote>\n<pre><code>$Computers = ( Get-ADComputer -Filter { Name -like \"FileServer*\" } ).Name\n\n$scriptBlock = {\n    param ([string]$Path)\n    \n    $noEmpties = [StringSplitOptions]::RemoveEmptyEntries\n\n    robocopy \/L \/E \/NDL \/NJH \/NJS \/NP \/NC \/BYTES $Path 'NoDestination' | \n    ForEach-Object{ \n        # If( !$_ ){ Continue }\n        $TempArr = $_.Split( \" `t\", 2, $noEmpties )\n        [PSCustomObject]@{\n            FilePath = $TempArr[1]\n            FileName = $TempArr[1].Split( '\\' )[-1]\n            Length   = [Int64]$TempArr[0]\n        }\n    } |\n    Sort-Object -Property Length | Select-Object -Last 32\n}\n\nTry\n{       \n    $Results = Invoke-Command -ComputerName $Computers -ScriptBlock $scriptBlock -ArgumentList 'C:\\Temp2' |\n    Group-Object -Property PSComputerName |\n    ForEach-Object{        \n        [PSCustomObject]@{\n            ComputerName = [String]$_.Name\n            'Server - IP' = \"$($_.Name) [$((Resolve-DnsName -Name $_.Name -Type A).IPAddress)]\" \n            'Top 32 Largest Files Size' = [Math]::Round( ($_.Group.Length | Measure-Object -Sum).Sum\/1GB, 2 )\n            'Top 32 Largest Files' = [Object[]]$_.Group | Select-Object FilePath,FileName,Length\n        }\n    }\n\n    # Export to CSV\n    $Results |\n    ForEach-Object{\n        $CSVFileName = $_.ComputerName + '-BigFiles.csv'\n        $_.'Top 32 Largest Files' | Export-Csv -Path $CSVFileName -NoTypeInformation\n    }\n}\nCatch\n{\n    $_ | Write-Error\n}\n\nNote: Again this is imperfect, I'm not as focused on efficiency and performance at the moment. I'm not yet sure if I could've eliminated a a loop or 2.\n<\/code><\/pre>\n<p>Because of your shifting requirements we have to pull 2 things from the RoboCopy output.<\/p>\n<ol>\n<li>The File Size<\/li>\n<li>The File Path<\/li>\n<\/ol>\n<p>Then from the file path we can derive the file name pretty easily.  As my previous work I&#8217;ve used some cagey <code>.Split()<\/code> invocations to get at that.  I&#8217;m sure that @Theo may have some RegEx approach&#8230;<\/p>\n<p>So the first thing is I have the remote side generating an object with only these properties. I&#8217;m doing the rest of the work locally.  The reason is I need both properties, we are no longer returning a single value from the remote machine.<\/p>\n<p>With the results I&#8217;m creating a new set of objects containing the ComputerName, the &#8216;Server IP&#8217;, the &#8216;Top 32 Largest Files Size&#8217; AND &#8216;Top 32 Largest Files&#8217;.  That last property is an array of objects with those same 3 properties.<\/p>\n<p>Now I can loop <code>$Results<\/code> and create the CSV files naming them according to the <code>$ComputerName<\/code> property.<\/p>\n<p>This is imperfect for sure.  One alternative might be to sub-delimit the FileNames with something like &#8220;;&#8221;  That would sufficiently flatten the object for the CSV file.  Though we&#8217;d have to abandon the Name &amp; length properties. Flat objects are easier to deal with, but a sub-delimited field then needs to be dealt with on input to whatever other process you use it for.<\/p>\n<p>Another question is if you really need to store the output in a CSV file.  JSON for example is much better for storing hierarchical objects.  <code>Export\\Import-Clixml<\/code> may also be of interest.  Of course and again it may depend on where you want to later consume that data etc&#8230;<\/p>\n<p>I think all this points to a need to shift your requirements to meet the task.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Using Robocopy to list the big files in remote computer and save it as ServerName.CSV <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] In your previous questions your starting point was the Get-DfsrMembership cmdlet. In this question you&#8217;ve switched to starting with Get-ADComputer. What others have been trying to point out is properties returned from Get-DfdMembership aren&#8217;t available. In particular $_.ContentPath isn&#8217;t available in this scenario. Furthermore, Get-ADComputer returns a Name property not ComputerName. That said, your &#8230; <a title=\"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\" aria-label=\"More on [Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1153,3099],"class_list":["post-11325","post","type-post","status-publish","format-standard","hentry","category-solved","tag-powershell","tag-robocopy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] In your previous questions your starting point was the Get-DfsrMembership cmdlet. In this question you&#8217;ve switched to starting with Get-ADComputer. What others have been trying to point out is properties returned from Get-DfdMembership aren&#8217;t available. In particular $_.ContentPath isn&#8217;t available in this scenario. Furthermore, Get-ADComputer returns a Name property not ComputerName. That said, your ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-26T18:43:33+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV\",\"datePublished\":\"2022-09-26T18:43:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\"},\"wordCount\":529,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"powershell\",\"robocopy\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\",\"name\":\"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-26T18:43:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb","og_description":"[ad_1] In your previous questions your starting point was the Get-DfsrMembership cmdlet. In this question you&#8217;ve switched to starting with Get-ADComputer. What others have been trying to point out is properties returned from Get-DfdMembership aren&#8217;t available. In particular $_.ContentPath isn&#8217;t available in this scenario. Furthermore, Get-ADComputer returns a Name property not ComputerName. That said, your ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/","og_site_name":"JassWeb","article_published_time":"2022-09-26T18:43:33+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV","datePublished":"2022-09-26T18:43:33+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/"},"wordCount":529,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["powershell","robocopy"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/","url":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/","name":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-26T18:43:33+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-using-robocopy-to-list-the-big-files-in-remote-computer-and-save-it-as-servername-csv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Using Robocopy to list the big files in remote computer and save it as ServerName.CSV"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/11325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=11325"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/11325\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=11325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=11325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=11325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}