I have some problems with these lines:
Invoke-Command -ComputerName $computerObject.Name -ScriptBlock {'{0:0.00}' -f ((Get-ChildItem $path -Recurse | Measure-Object -Property Length -sum).sum)}
I'm getting nothing. But if I use instead of $path
, c:\users\pa27dd7n\documents
the output is 21830841828,00
The return of $path.gettype()
is:
name:string basetype: system.object
Current code:
$computers = Get-ADComputer -SearchBase "OU=......" -filter "*" -Properties name,description,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | sort-object description
$ADUsers = Get-ADUser -Filter * -SearchBase "OU=........" | Where-Object {$PSItem.enabled -eq "True"} | Sort-Object name
I add the property to the computers to keep login of the right user for the computer:
$computers | foreach {Add-Member -InputObject $PSItem -NotePropertyName MainUserSamAccountName -NotePropertyValue "" -Force}
From $ADUsers
I'm getting login of the user I need.
When I got everything:
$computerObject = $computers.Get($a)
- in the loop
So, When I got that login:
$path = "c:\users\$computerObject.MainUserSamAccountName\documents"
This way I got the path of the directory users's documents.