Question on Get-FileShare Cmdlet RRS feed

  • Question

  • Good afternoon everyone...

    Let me start by stating that I am in no way a master of scripting.  I do it only when I have a large project that requires one so please be kind.

    My challenge at the moment is that I need to enumerate all shares on a number of machines.  Preferably through an input file and output the results into a file on a local drive named $input.txt / $input being the computer name in this instance.

    The problem that I have is that I cannot figure out how to pass the variable $input into the -FriendlyName value.  If I can get that piece figured out, I'm ready to start rolling with the remainder of the script.

    By the way - the value works fine when passed as a string rather than a variable but I do need to do this across several hundred PCs.  I have tried with single and double quotes, tried brackets, parenthesis and all that fun stuff...

    Any help would be very much appreciated!


    $input= import-csv "c:\temp\scripts\shares\pcs.csv"
    ForEach ($name in $input){
    echo $input
    Get-FileShare (Get-StorageFileServer -FriendlyName $input) >> c:\temp\scripts\shares\$input.txt


    Tuesday, October 2, 2018 9:45 PM

All replies

  • Please format your code as code here in the forum. Thanks.

    If you have a collection of "items" and you want to iterate over it you have to "provide" a single item inside the loop! Something like this could be a start

    $input = Import-Csv -Path 'c:\temp\scripts\shares\pcs.csv'
    $output = 'c:\temp\scripts\shares\output.txt'
    ForEach ($name in $input){
        echo $name
        Get-FileShare (Get-StorageFileServer -FriendlyName $name) |
            Out-File -FilePath $output -Append
    In your code you're writing the output to the same file where the input comes from ...

    Live long and prosper!


    • Edited by BOfH-666 Tuesday, October 2, 2018 10:40 PM
    Tuesday, October 2, 2018 10:39 PM