PoshCode Archive  Artifact Content

Artifact b23a9275562da60780ebc1732c571357abcb5b6b49426226cdcc744ca840cf50:

  • File Step-1.ps1 — part of check-in [198f19ee91] at 2018-06-10 13:49:33 on branch trunk — Lab 7 (user: Don Jones size: 1330)

# encoding: ascii
# api: powershell
# title: Step 1
# description: Lab 7
# version: 0.1
# type: function
# author: Don Jones
# license: CC0
# function: Get-ShareInfo
# x-poshcode-id: 5067
# x-archived: 2014-04-13T11:56:20
# x-published: 2014-04-09T18:13:00
#
#
 function Get-ShareInfo {
    param(
        [string[]]$ComputerName,

        [string]$ErrorLogFile
    )

    foreach ($computer in $ComputerName) {

        $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
} #function Get-ShareInfo


Get-ShareInfo -ComputerName dc,win81 -ErrorLogFile c:\errors.txt