powershell

sethayes

·

Get-NetworkFolders

·

Powershell

·

Total Size: 5.2 KB

·

·

Created: 6 months ago

·

Edited: 6 months ago

Set-ExecutionPolicy bypass -Force -confirm:$false # Get the User Profile Folder Paths from the Registry # Also, get the size of the Folder Paths $doc = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Personal -ErrorAction SilentlyContinue).Personal $docSize = [math]::Round([double]((Get-ChildItem "$($doc)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024 / 1024),2) $desk = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop -ErrorAction SilentlyContinue).Desktop $deskSize = [math]::Round([double]((Get-ChildItem "$($desk)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024 / 1024),2) $fave = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Favorites -ErrorAction SilentlyContinue).Favorites $faveSize = [math]::Round([double]((Get-ChildItem "$($fave)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024),2) $music = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Music" -ErrorAction SilentlyContinue)."My Music" $musicSize = [math]::Round([double]((Get-ChildItem "$($music)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024 / 1024),2) $pic = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Pictures" -ErrorAction SilentlyContinue)."My Pictures" $picSize = [math]::Round([double]((Get-ChildItem "$($pic)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024 / 1024),2) $vid = (Get-ItemProperty -Path Registry::"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "My Video" -ErrorAction SilentlyContinue)."My Video" $vidSize = [math]::Round([double]((Get-ChildItem "$($vid)" -recurse -force | measure-object -property length -sum).sum / 1024 / 1024 / 1024),2) # Name the WMI NameSpace and Class $nameSpace = 'MSI' $class = 'NetworkFolders' # Does Namespace already exist? Write-Verbose "Getting WMI Namespace $nameSpace" $nsFilter = "Name = '$nameSpace'" $nsExist = Get-WmiObject -Namespace root -Class __namespace -Filter $nsFilter # Namespace does not nsExist If ($nsExist -eq $null) { Write-Verbose "$nameSpace Namespace does not exist. Creating new Namespace . . ." # Create Namespace $rootNamespace = [wmiClass]'root:__namespace' $newNamespace = $rootNamespace.CreateInstance() $newNamespace.Name = $nameSpace $newNamespace.Put() } # Does Class already exist? Write-Verbose "Getting $Class Class" $classExist = Get-CimClass -Namespace root/$nameSpace -ClassName $class -ErrorAction SilentlyContinue # Class does not exist If ($classExist -eq $null) { Write-Verbose "$class Class does not exist. Creating new class . . ." # Create Class $newClass = New-Object System.Management.ManagementClass("root\$nameSpace", [string]::Empty, $null) $newClass.name = $class $newClass.Qualifiers.Add("Static", $true) $newClass.Properties.Add("ComputerName", [System.Management.CimType]::String, $false) $newClass.Properties["ComputerName"].Qualifiers.Add("Key", $true) $newClass.Properties.Add("Documents", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Documents_Size", [System.Management.CimType]::real64, $false) $newClass.Properties.Add("Desktop", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Desktop_Size", [System.Management.CimType]::real64, $false) $newClass.Properties.Add("Favorites", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Favorites_Size", [System.Management.CimType]::real64, $false) $newClass.Properties.Add("Music", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Music_Size", [System.Management.CimType]::real64, $false) $newClass.Properties.Add("Pictures", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Pictures_Size", [System.Management.CimType]::real64, $false) $newClass.Properties.Add("Video", [System.Management.CimType]::String, $false) $newClass.Properties.Add("Video_Size", [System.Management.CimType]::real64, $false) $newClass.Put() } # Add all the Folders/Sizes to WMI $wmiPath = 'root\' + $nameSpace + ':' + $class $wmiInstance = ([wmiclass]$wmiPath).CreateInstance() $wmiInstance.ComputerName = $ENV:COMPUTERNAME $wmiInstance.Documents = $doc $wmiInstance.Documents_Size = $docSize $wmiInstance.Desktop = $desk $wmiInstance.Desktop_Size = $deskSize $wmiInstance.Favorites = $fave $wmiInstance.Favorites_Size = $faveSize $wmiInstance.Music = $music $wmiInstance.Music_Size = $musicSize $wmiInstance.Pictures = $pic $wmiInstance.Pictures_Size = $picSize $wmiInstance.Video = $vid $wmiInstance.Video_Size = $vidSize $wmiInstance.Put() Clear-Variable -Name wmiInstance

0 bits

125 views

Are you sure you want to delete?