Share via


Get Server Share Information Using PowerShell


  Get Server Share Information Using PowerShell


Requirement

We need to upgrade all our Windows 2003 server to Windows 2012 so we need to make inventory using PowerShell. The inventory should have below and we need it in two difference CSV

  1. Server Name
  2. Shared Path - Including Hidden

Help

Before building the script let's explore the commands and help. Let's use WMI Object to get Share information

Help Get-WmiObject -Full

Help Get-WmiObject -Parameter Class

Help Get-WmiObject -Parameter Filter

Help Get-WmiObject -Parameter Query

Help about_Workflows

Solution

The list has close to 800 servers. That's good to know before fetching information. Let's use Workflow foreach paralle to speed up the action.

workflow GetShareInformation {

   param([string[]]$computers)

   foreach â€“parallel ($computer in $computers){

     InlineScript {

       Get-WmiObject â€“Class Win32_Share â€“ComputerName $using:computer -Filter "type=0 AND name like '%[^$]'" | Select *

     }

   }



$machine = Get-Content C:\Temp\Servers.txt
GetShareInformation -computers $machine | Select __Server , Path    | Export-Csv C:\Temp\ShareInformation.csv -NoTypeInformation -Encoding UTF8

Screenshot

WMI Explorer

https://wmie.codeplex.com/

PowerShell Syntax Explorer

([WMIClass]"Win32_Share").GetText('MOF')