-
-
Save irwins/9d7754e94d4161e3c56699d35a53ba59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Author: I. Strachan | |
Version: | |
Version History: | |
Purpose: Get File Servers storage configuration | |
#> | |
#region FileServers to process | |
$Servers = @" | |
ComputerName | |
DC-DSC-01 | |
MEM-DSC-01 | |
"@ | ConvertFrom-Csv -Delimiter "`t" | |
#endregion | |
#region import saved credential and initialize variables | |
#Jaap Brassers blog on saving credentials. | |
#http://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell/ | |
$Hash = Import-CliXml -Path "${env:\userprofile}\Hash.Cred" | |
$cred = $Hash.'pshirwin-admin' | |
$exportDate = Get-Date -Format ddMMyyyy | |
$xlsxFile = ".\export\storage\PSHIRWIN - StorageReport - $($exportDate).xlsx" | |
$null = Get-SmbShare | Get-SmbShareAccess | |
#endregion | |
#region Helper functions and scriptblock | |
filter Get-CapacitySize { | |
'{0:N2} {1}' -f $( | |
if ($_ -lt 1kb) { $_, 'Bytes' } | |
elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } | |
elseif ($_ -lt 1gb) { ($_/1mb), 'MB' } | |
elseif ($_ -lt 1tb) { ($_/1gb), 'GB' } | |
elseif ($_ -lt 1pb) { ($_/1tb), 'TB' } | |
else { ($_/1pb), 'PB' } | |
) | |
} | |
$sbStorage = { | |
[PSCustomObject]@{ | |
Volume = $(Get-Volume | Select-Object *) | |
SMBShare = $(Get-SmbShare | Select-Object *) | |
SMBShareAccess = $(Get-SmbShare | Get-SmbShareAccess) | |
SMBShareNTFS = $(Get-SmbShare | | |
Where-Object{ $_.Name -ne 'IPC$'} | | |
Get-Acl | | |
Select-Object @{Name='Path';Expression={($_.Path).Replace('Microsoft.PowerShell.Core\FileSystem::','')}}, | |
Owner,Access | |
) | |
Disk = $(Get-Disk | Select-Object *) | |
VSSShadows = $(vssadmin.exe list Shadows) | |
VSSWriters = $(vssadmin.exe list Writers) | |
} | |
} | |
#endregion | |
#region Main | |
$snapshotStorage = $Servers | | |
ForEach-Object{ | |
Invoke-Command -ComputerName $_.ComputerName -ScriptBlock $sbStorage -Credential $cred | |
} | |
#endregion | |
#region Export snapshot to XML | |
$snapshotStorage | Export-Clixml .\export\storage\StorageSnapshot-$($exportDate).xml -Encoding UTF8 | |
#endregion | |
#region Create CSV reports | |
#export Server names to xlsxFile | |
$Servers| | |
Export-Excel -Path $xlsxFile -WorkSheetname Servers -AutoSize -BoldTopRow | |
#region Get Volume Names | |
$snapshotStorage | | |
ForEach-Object{ | |
$ComputerName = $_.PSComputerName | |
$_.Volume | | |
ForEach-Object{ | |
[PSCustomObject]@{ | |
ComputerName = $ComputerName | |
DriveLetter = $_.Driveletter | |
FileSystemLabel = $_.FileSystemLabel | |
DiskSize = $_.Size | Get-CapacitySize | |
UsedSpace = $_.SizeRemaining | Get-CapacitySize | |
FreeSpace = ($_.Size - $_.SizeRemaining) | Get-CapacitySize | |
} | |
} | |
} | | |
Export-Csv .\export\storage\FS_VolumeNames-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_VolumeNames-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname VolumeNames -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#region Get Shares | |
$snapshotStorage | | |
ForEach-Object{ | |
$ComputerName = $_.PSComputerName | |
$_.SMBShare | | |
ForEach-Object{ | |
[PSCustomObject]@{ | |
ComputerName = $ComputerName | |
Name = $_.Name | |
Path = $_.Path | |
Description = $_.Description | |
ShareState = $_.ShareState | |
} | |
} | |
}| | |
Export-Csv .\export\storage\FS_SMBShares-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_SMBShares-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname SMBShares -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#region Get Sharesaccess | |
$snapshotStorage | | |
ForEach-Object{ | |
$ComputerName = $_.PSComputerName | |
$_.SMBShareAccess | | |
ForEach-Object{ | |
[PSCustomObject]@{ | |
ComputerName = $ComputerName | |
Name = $_.Name | |
AccountName = $_.AccountName | |
AccessControlType = $_.AccessControlType | |
AccessRight = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.SmbShare.ShareAccessRight]$_.AccessRight | |
} | |
} | |
}| | |
Export-Csv .\export\storage\FS_SMBSharesAccess-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_SMBSharesAccess-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname SMBSharesAccess -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#region Get Shares NTFS Access | |
$snapshotStorage | | |
ForEach-Object{ | |
$ComputerName = $_.PSComputerName | |
$_.SMBShareNTFS | | |
ForEach-Object{ | |
$fullPathName = $_.Path | |
$pathOwner = $_.Owner | |
$_.Access| | |
ForEach-Object{ | |
[PSCustomObject]@{ | |
ComputerName = $ComputerName | |
Path = $fullPathName | |
Owner = $pathOwner | |
IdentityReference = $_.IdentityReference | |
FileSystemRights = $_.FileSystemRights | |
AccessControlType = $_.AccessControlType | |
IsInherited = $_.IsInherited | |
InheritanceFlags = $_.InheritanceFlags | |
PropagationFlags = $_.PropagationFlags | |
} | |
} | |
} | |
}| | |
Export-Csv .\export\storage\FS_SMBSharesNTFS-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_SMBSharesNTFS-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname SMBSharesNTFS -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#region VSS Shadow copies | |
$shadowCopyProperties = [Ordered]@{ | |
ShadowCopySetID = '' | |
CreationTime = '' | |
ShadowCopyID = '' | |
OriginalVolume = '' | |
ShadowCopyVolume = '' | |
Machine = '' | |
Provider = '' | |
Type = '' | |
Attributes = '' | |
} | |
$snapshotStorage | | |
ForEach-Object{ | |
foreach($line in $_.VSSShadows){ | |
switch($line){ | |
{$_ -match 'Contents of shadow copy set ID:'} | |
{ | |
$shadowCopy = New-Object -TypeName psobject -Property $shadowCopyProperties | |
$shadowCopy.ShadowCopySetID = $_.Substring(32).Trim() | |
} | |
{$_ -match ' Contained 1 shadow copies at creation time:'} | |
{ $shadowCopy.CreationTime = $_.Substring(46).Trim() } | |
{$_ -match ' Shadow Copy ID:'} | |
{ $shadowCopy.ShadowCopyID = $_.Substring(21).Trim() } | |
{$_ -match ' Original Volume:'} | |
{ $shadowCopy.OriginalVolume = $_.Substring(26).Trim() } | |
{$_ -match ' Shadow Copy Volume:'} | |
{ $shadowCopy.ShadowCopyVolume = $_.Substring(29).Trim() } | |
{$_ -match ' Originating Machine: '} | |
{ $shadowCopy.Machine = $_.Substring(30).Trim() } | |
{$_ -match ' Provider:'} | |
{ $shadowCopy.Provider = $_.Substring(19).Trim() } | |
{$_ -match ' Type:'} | |
{ $shadowCopy.Type = $_.Substring(15).Trim() } | |
{$_ -match ' Attributes:'} | |
{ | |
$shadowCopy.Attributes = $_.Substring(21).Trim() | |
[PSCustomObject]$shadowCopy | |
} | |
} | |
} | |
}| | |
Export-Csv .\export\storage\FS_VSSShadowCopies-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_VSSShadowCopies-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname 'VSS Shadow copies' -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#region VSS Writers | |
$shadowWriterProperties = [Ordered]@{ | |
ComputerName = '' | |
Name = '' | |
ID = '' | |
InstanceID = '' | |
State = '' | |
LastError = '' | |
} | |
$snapshotStorage | | |
ForEach-Object{ | |
$ComputerName = $_.PSComputerName | |
foreach($line in $_.VSSWriters){ | |
switch($line){ | |
{$_ -match 'Writer name:'} | |
{ | |
$shadowWriter = New-Object -TypeName psobject -Property $shadowWriterProperties | |
$shadowWriter.ComputerName = $ComputerName | |
$shadowWriter.Name = $_.Substring(12).Replace("'",'').Trim() | |
} | |
{$_ -match ' Writer Id:'} | |
{ $shadowWriter.ID = $_.Substring(13).Trim() } | |
{$_ -match ' Writer Instance Id:'} | |
{ $shadowWriter.InstanceID = $_.Substring(22).Trim() } | |
{$_ -match ' State: '} | |
{ $shadowWriter.State = $_.Substring(13).Trim() } | |
{$_ -match ' Last error:'} | |
{ | |
$shadowWriter.LastError = $_.Substring(14).Trim() | |
[PSCustomObject]$shadowWriter | |
} | |
} | |
} | |
}| | |
Export-Csv .\export\storage\FS_VSSShadowWriters-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation | |
#Export to xlsx file | |
Import-Csv .\export\storage\FS_VSSShadowWriters-$($exportDate).csv -Encoding UTF8 -Delimiter "`t" | | |
Export-Excel -Path $xlsxFile -WorkSheetname 'VSS Shadow writers' -AutoSize -BoldTopRow -FreezeTopRow | |
#endregion | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment