Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Desktop size

$
0
0

Hi, as new member on forum I would like to ask you guys for help.

 

I want to find users desktop size from different PCs. What I've done so far: From list I read pc, if it is ping able then I find which user is logged on that PC, with this information I browse to desktop dir to find size and at the end everything is stored in csv for further analysis and calculations.

___________

Code is:

___________

filter Get-DBSize
{
$ping = Get-WmiObject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
if ($ping.StatusCode -eq 0)
{
function Get-LoggedOnUsers {
$Computers=$_
$Computers | foreach {$((Get-WmiObject Win32_ComputerSystem | Select UserName | Format-Table -HideTableHeaders | Out-String) -split ‘\\’)[1]}
}
$logeduser = Get-LoggedOnUsers
$path1 = "c$\Users\$logeduser\Desktop"
$size = Get-ChildItem -Path "\\$($_)\$path1" -Recurse -Force | Measure-Object -property length -sum
New-Object PSObject -Property @{
ComputerName = $_
FolderPath = "\\$($_)\c$\Users\$logeduser\Desktop"

FolderSize = "{0:N2} GB" -f ($size.sum / 1GB)
}}
Else {
New-Object PSObject -Property @{
ComputerName = $_
FolderPath = "NODE OFFLINE"}}}

Get-Content C:\powershell\workstations.txt | Get-DBSize | Select-Object ComputerName,FolderPath,FolderSize | Export-Csv -NoTypeInformation C:\powershell\testdarko.csv

____________________

after executing the code there is error:

Get-ChildItem : Illegal characters in path.
At line:15 char:9
+ $size = Get-ChildItem -Path "\\$($_)\$path1" -Recurse -Force | Measur ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], ArgumentException
   + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.G
   etChildItemCommand

Get-ChildItem : Illegal characters in path.
At line:15 char:9
+ $size = Get-ChildItem -Path "\\$($_)\$path1" -Recurse -Force | Measur ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], ArgumentException
   + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.G
   etChildItemCommand

 

If I put some other dir like c:\temp script is running Ok

Thank you very much in advance
regards
Darko 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles