Microsoft Virtualization Discussions

Powershell - Get a list of files > 4GB, all volumes

Doc_McJust
102 Views

I am trying to create a powershell script that will give me a list of every file in our cluster that is greater than 4GB.

 

The script must include file path information and output to a .txt file.

 

So far, I only have the bones of a script and I've been testing it on my work PC.

 

The final version will likely have to be run on the domain controller, but I am not sure how to build the script from the context of the DC.

 

$path = "C:\Users\LJONAH"
$sizeThreshold = 10
$outputPath = "C:\temp\OIS_large_files.txt"
Get-ChildItem -Path $path -Recurse -File -ErrorAction SilentlyContinue |
Where-Object {$_.Length / 1MB -gt $sizeThreshold}| Select-Object FullName, @{Name="Size GB";Expression={ "{0:N0}" -f ($_.Length / 1GB) }} | Out-File -FilePath $outputPath

1 ACCEPTED SOLUTION

RobDBA
38 Views

Using the NetApp API:

function Read-NetAppVolDir {
	<#
	.SYNOPSIS
			NetApp Directory Listing

	.Description
			This is a helper script to make reading folder contents in NetApp volumes more intuitive.

	.Outputs
			DataONTAP.C.Types.File.FileInfo
	#>

	param(
			[parameter(mandatory)] [string]$Volume,
			[string[]]$SubFolder,
			[switch]$Recurse
	)

	if ($SubFolder) {
			foreach ($sub in $SubFolder) {
					Get-NcVol $Volume | Get-Ncfile | Foreach-Object {
							"`n    Directory: $($_.Path)/$sub/"
							$files=$_ | Read-NcDirectory ("$($_.Path)"+'/'+$sub)
							if ($Recurse) {
								$files | Where-Object Name -notlike '[.]*'
								$files | Where-Object { $_.Type -eq 'directory' -and $_.Name -notlike '[.]*' } | Foreach-Object {
									Read-NetAppVolDir $Volume "$sub/$($_.Name)" -Recurse
								}
							} else {
								$files
							}
					}
			}
	} else {
			Get-NcVol $Volume | Foreach-Object {
					"`n    Directory: $($_.JunctionPath)/"
					$files=$_ | Read-NcDirectory
					if ($Recurse) {
						$files | Where-Object Name -notlike '[.]*'
						$files | Where-Object { $_.Type -eq 'directory' -and $_.Name -notlike '[.]*' } | Foreach-Object {
							Read-NetAppVolDir $Volume $_.Name -Recurse
						}
					} else {
						$files
					}
			}
	}
}
Get-NcVol | % { Read-NetAppVolDir $_.Name -Recurse } | ? Size -gt 4gb

View solution in original post

1 REPLY 1

RobDBA
39 Views

Using the NetApp API:

function Read-NetAppVolDir {
	<#
	.SYNOPSIS
			NetApp Directory Listing

	.Description
			This is a helper script to make reading folder contents in NetApp volumes more intuitive.

	.Outputs
			DataONTAP.C.Types.File.FileInfo
	#>

	param(
			[parameter(mandatory)] [string]$Volume,
			[string[]]$SubFolder,
			[switch]$Recurse
	)

	if ($SubFolder) {
			foreach ($sub in $SubFolder) {
					Get-NcVol $Volume | Get-Ncfile | Foreach-Object {
							"`n    Directory: $($_.Path)/$sub/"
							$files=$_ | Read-NcDirectory ("$($_.Path)"+'/'+$sub)
							if ($Recurse) {
								$files | Where-Object Name -notlike '[.]*'
								$files | Where-Object { $_.Type -eq 'directory' -and $_.Name -notlike '[.]*' } | Foreach-Object {
									Read-NetAppVolDir $Volume "$sub/$($_.Name)" -Recurse
								}
							} else {
								$files
							}
					}
			}
	} else {
			Get-NcVol $Volume | Foreach-Object {
					"`n    Directory: $($_.JunctionPath)/"
					$files=$_ | Read-NcDirectory
					if ($Recurse) {
						$files | Where-Object Name -notlike '[.]*'
						$files | Where-Object { $_.Type -eq 'directory' -and $_.Name -notlike '[.]*' } | Foreach-Object {
							Read-NetAppVolDir $Volume $_.Name -Recurse
						}
					} else {
						$files
					}
			}
	}
}
Get-NcVol | % { Read-NetAppVolDir $_.Name -Recurse } | ? Size -gt 4gb
Public