# 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