\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n <\/p>","upvoteCount":0,"datePublished":"2020-10-26T17:55:47.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
$Path = \"C:\\Users\"\n$LogPath = \"C:\\Downloads\\reports\"\nGet-ChildItem $Path -force -Recurse | Select Name,Directory,@{Name=\"Owner\";Expression={(Get-ACL $_.Fullname).Owner}},CreationTime,LastAccessTime | Export-Csv $LogPath\\FileFolderOwner.csv -NoTypeInformation\n<\/code><\/pre>\nThanks for the code insert Tip.<\/p>\n
We do use you Active Directory. I can get the file owner, but I was hoping to get the email address as well.<\/p>","upvoteCount":0,"datePublished":"2020-10-26T18:02:00.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/4","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-Marty61:<\/div>\n
\n$Path = \"C:\\Users\"\n$LogPath = \"C:\\Downloads\\reports\"\nGet-ChildItem $Path -force -Recurse | Select Name,Directory,@{Name=\"Owner\";Expression={(Get-ACL $_.Fullname).Owner}},CreationTime,LastAccessTime | Export-Csv $LogPath\\FileFolderOwner.csv -NoTypeInformation\n<\/code><\/pre>\nThanks for the code insert Tip.<\/p>\n
We do use you Active Directory. I can get the file owner, but I was hoping to get the email address as well.<\/p>\n<\/blockquote>\n<\/aside>\n
not from the ‘get-acl’ cmdlet, you have to query AD.<\/p>\n
e.g. (this assumes you have the AD module installed)<\/p>\n
$Path = \"C:\\Users\"\n$LogPath = \"C:\\Downloads\\reports\"\nGet-ChildItem $Path -force -Recurse | \nSelect Name,Directory,\n@{Name=\"Owner\";Expression={(Get-ACL $_.Fullname).Owner}},\n@{Name=\"OwnerEmail\";Expression={(get-aduser (Get-ACL $_.Fullname).Owner -pr emailaddress).emailaddress}},\nCreationTime,LastAccessTime | \nExport-Csv $LogPath\\FileFolderOwner.csv -NoTypeInformation\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-26T18:07:44.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"also look into splatting / pscustomobjects, much better to read.<\/p>\n
$Path = \"C:\\Users\"\n$LogPath = \"C:\\Downloads\\reports\"\n$data = Get-ChildItem $Path -force -Recurse\n\n$report = \nforeach ($file in $data) {\n $owner = (Get-ACL $file.Fullname).Owner\n $email = $null\n $email = (Get-aduser $owner -properties emailaddress).emailaddress\n\n [pscustomobject]@{\n Name = $file.name\n Directory = $file.directory\n CreationTime = $file.CreationTime\n LastAccessTime = $file.LastAccessTime\n Owner = $owner\n OwnerEmail = if ($email) { $email }else { '' }\n }\n}\n\n$report =\nExport-Csv \"$LogPath\\FileFolderOwner.csv\" -NoTypeInformation\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-26T18:13:12.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Thank you . Would I need to strip the Domain off of the username to get the email? The email field came back blank. There were no errors at execution.<\/p>","upvoteCount":0,"datePublished":"2020-10-26T18:20:45.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/7","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-Marty61:<\/div>\n
\nThank you . Would I need to strip the Domain off of the username to get the email? The email field came back blank. There were no errors at execution.<\/p>\n<\/blockquote>\n<\/aside>\n
possibly, I’m just giving you the concept you still have to put some effort in yourself ;¬)<\/p>","upvoteCount":0,"datePublished":"2020-10-26T18:31:12.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Thank You. I appreciate the help!<\/p>","upvoteCount":0,"datePublished":"2020-10-26T18:34:59.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/9","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-Marty61:<\/div>\n
\nThank You. I appreciate the help!<\/p>\n<\/blockquote>\n<\/aside>\n
give it a shot, if you get stuck feel free to post what you have tried and we’ll help more.<\/p>","upvoteCount":1,"datePublished":"2020-10-26T18:36:29.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Will Do! I truly appreciate the help yo have given me.<\/p>","upvoteCount":1,"datePublished":"2020-10-26T18:38:00.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/11","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"
import-csv C:\\Users\\Downloads\\FileFolderOwner.csv | \nForEach-Object {\nGet-ADUser -Filter \"samaccountname -eq '$($_.owner)'\" -Properties EmailAddress \n} | select SamAccountName,$($_.Name),EmailAddress | export-csv C:\\Users\\Downloads\\file-out.csv\n<\/code><\/pre>\nI am reading an Import file.<\/p>\n
The first column has a header called Name, the second column has a header of Owner.<\/p>\n
I am using the owner to get the active directory email address for all the rows in the csv. This is working and I am seeing it in my export file.<\/p>\n
I would like to include the date from the name column of my import file into my export file it won’t work.<\/p>\n
I get the following error<\/p>\n
select : The value of a parameter was null; one of the following types was expected: {System.String, \nSystem.Management.Automation.ScriptBlock}. \nAt line:4 char:5<\/p>\n
\n} | select SamAccountName,$($_.Name),EmailAddress | export-csv C:\\Users\\mspeare\\ …<\/li>\n \n<\/code><\/pre>\n<\/li>\nCategoryInfo : InvalidArgument: ( [Select-Object], NotSupportedException<\/li>\n FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand<\/li>\n<\/ul>\nIf I remove $($_.Name) the script runs with no error.<\/p>","upvoteCount":0,"datePublished":"2020-10-29T16:12:30.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/12","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"
its because you dont need the $() you only need that in the filter<\/p>\n
mport-csv C:\\Users\\Downloads\\FileFolderOwner.csv | \nForEach-Object {\nGet-ADUser -Filter \"samaccountname -eq '$($_.owner)'\" -Properties EmailAddress \n} | select SamAccountName,$_.Name,EmailAddress | export-csv C:\\Users\\Downloads\\file-out.csv\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-29T16:17:06.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/13","author":{"@type":"Person","name":"spiceuser-lhb9l","url":"https://community.spiceworks.com/u/spiceuser-lhb9l"}},{"@type":"Answer","text":"if you are using samaccountname you also dont need the filter<\/p>\n
import-csv C:\\Users\\Downloads\\FileFolderOwner.csv | \nForEach-Object {\nGet-ADUser $_.owner -Properties EmailAddress \n} | select SamAccountName,$_.Name,EmailAddress | export-csv C:\\Users\\Downloads\\file-out.csv\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2020-10-29T16:21:54.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/14","author":{"@type":"Person","name":"spiceuser-lhb9l","url":"https://community.spiceworks.com/u/spiceuser-lhb9l"}},{"@type":"Answer","text":"This has been commented to me many a times and On my iPhone 11 using the Spiceworks app you don’t have the option in the editor to insert code. \nAll you have is quote, tag, insert picture, and hyperlink. \nAny ideas how you can insert code, \nTIA<\/p>","upvoteCount":0,"datePublished":"2020-10-29T16:23:10.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/15","author":{"@type":"Person","name":"pauljones9002","url":"https://community.spiceworks.com/u/pauljones9002"}},{"@type":"Answer","text":"
import-csv C:\\Users\\Downloads\\FileFolderOwner.csv | \nForEach-Object {\nGet-ADUser $_.owner -Properties EmailAddress \n} | select SamAccountName,$_.Name,EmailAddress | export-csv C:\\Users\\Downloads\\file-out.csv\n<\/code><\/pre>\nI am still getting the same error. <\/p>","upvoteCount":0,"datePublished":"2020-10-29T16:47:55.000Z","url":"https://community.spiceworks.com/t/trying-to-get-ad-email-address-for-a-file-owner/780001/16","author":{"@type":"Person","name":"spiceuser-marty61","url":"https://community.spiceworks.com/u/spiceuser-marty61"}},{"@type":"Answer","text":"