Hi All
I am thoroughly enjoying working my way (slowly) thrrough the above book but I am having a problem completing the chapter “An Interlude: Changing Your Approach”.
In the function “Get-UserHomeFolderInfo”, there is line “$user = Get-ADUser @params”. When i run that function I get an error “Get-ADUser : Cannot find an object with identity: ‘administrator.HOME’ under: 'DC=home”, which is unexpected. Any ideas why I am getting this and not the expected behaviour?
function Get-FolderSize { [CmdletBinding()] Param( [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string[]]$Path ) BEGIN {} PROCESS { ForEach ($folder in $path) { Write-Verbose "Checking $folder" if (Test-Path -Path $folder) { Write-Verbose " + Path exists" $params = @{'Path'=$folder 'Recurse'=$true 'File'=$true} $measure = Get-ChildItem @params | Measure-Object -Property Length -Sum [pscustomobject]@{'Path'=$folder 'Files'=$measure.count 'Bytes'=$measure.sum} } else { Write-Verbose " - Path does not exist" [pscustomobject]@{'Path'=$folder 'Files'=0 'Bytes'=0} } #if folder exists } #foreach } #PROCESS END {} } #function function Get-UserHomeFolderInfo { [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$HomeRootPath ) BEGIN {} PROCESS { Write-Verbose "Enumerating $HomeRootPath" $params = @{'Path'=$HomeRootPath 'Directory'=$True} ForEach ($folder in (Get-ChildItem @params)) { Write-Verbose "Checking $($folder.name)" $params = @{'Identity'=$folder.name 'ErrorAction'='SilentlyContinue'} $user = Get-ADUser @params if ($user) { Write-Verbose " + User exists" $result = Get-FolderSize -Path $folder.fullname [pscustomobject]@{'User'=$folder.name 'Path'=$folder.fullname 'Files'=$result.files 'Bytes'=$result.bytes 'Status'='OK'} } else { Write-Verbose " - User does not exist" [pscustomobject]@{'User'=$folder.name 'Path'=$folder.fullname 'Files'=0 'Bytes'=0 'Status'="Orphan"} } #if user exists } #foreach } #PROCESS END {} }
Powershell cmdline output:
PS C:\Dev\Powershell> Get-UserHomeFolderInfo -verbose
cmdlet Get-UserHomeFolderInfo at command pipeline position 1
Supply values for the following parameters:
HomeRootPath: c:\users
VERBOSE: Enumerating c:\users
VERBOSE: Checking Administrator
VERBOSE: + User exists
VERBOSE: Checking C:\users\Administrator
VERBOSE: + Path exists
User : Administrator
Path : C:\users\Administrator
Files : 189
Bytes : 7623892
Status : OK
: Checking administrator.HOME
ser : Cannot find an object with identity: ‘administrator.HOME’ under: 'DC=home,DC=kelly,DC=za
rogram Files\WindowsPowerShell\Modules\FolderInfo\FolderInfo.psm1:50 char:21
$user = Get-ADUser @params
~~~~~~~~~~~~~~~~~~
ategoryInfo : ObjectNotFound: (administrator.HOME:ADUser) [Get-ADUser], ADIdentityNot
ullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNo
soft.ActiveDirectory.Management.Commands.GetADUser
: + User exists
: Checking C:\users\administrator.HOME
: + Path exists
: administrator.HOME
: C:\users\administrator.HOME
: 287
: 12951945
: OK