PoshCode Archive  Artifact [aed1c197eb]

Artifact aed1c197ebf4dc26909cb580f31c7e21070e2cde99efd3286d70103499902617:

  • File Get-ShareInfo.ps1 — part of check-in [6a71eb77f6] at 2018-06-10 13:49:35 on branch trunk — Class lab 8 (user: unknown size: 1601)

# encoding: ascii
# api: powershell
# title: 
# description: Class lab 8
# version: 0.1
# type: function
# license: CC0
# function: Get-ShareInfo
# x-poshcode-id: 5068
# x-archived: 2014-04-13T11:56:25
#
#
 function Get-ShareInfo {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$True,HelpMessage='The computer name, duh',ValueFromPipeline=$True)]
        [string[]]$ComputerName,

        [Parameter(HelpMessage='A log file name')]
        [string]$ErrorLogFile = 'c:\errors.txt'
    )
    PROCESS {
        foreach ($computer in $ComputerName) {
            Write-Verbose "Connecting to $computer"
            $shares = Get-CimInstance -ClassName Win32_Share -ComputerName $Computer -filter "Path<>''"

            foreach ($share in $shares) {

                $sharename = $share.path -replace "\\","\\"
                $directory = Get-CimInstance -ClassName Win32_Directory -Filter "Name='$($sharename)'"

                $properties = @{'ComputerName'=$Computer;
                                'Name'=$share.name;
                                'Path'=$share.path;
                                'Caption'=$share.caption;
                                'Readable'=$directory.readable;
                                'Writable'=$directory.writable}
                $output = New-Object -TypeName PSObject -Property $properties
                Write-Output $output

            } #foreach share

        } #foreach computer
    } #PROCES
} #function Get-ShareInfo


"dc","win81" | Get-ShareInfo -Verbose | export-csv output.csv