I am trying to use Get-Content and create a variable that will fill out a directory pathname based on each line of my file.
I have a long list of users in a .csv file and I want to check each of their usernames to get directory size.
The script works if I remove the $username variable and type the username manually at the end of $startdirectory.
$username = Get-Content 'C:\Scripts\AvayaUsers.csv'
$startDirectory = '\\xx\xxxx\xxxxxxxxxxx\users\$username'
$directoryItems = Get-ChildItem $startDirectory | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
foreach ($i in $directoryItems)
{
$subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
$i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
}