Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 从PowerShell中的用户帐户提取电子邮件地址_String_Powershell_Data Structures - Fatal编程技术网

String 从PowerShell中的用户帐户提取电子邮件地址

String 从PowerShell中的用户帐户提取电子邮件地址,string,powershell,data-structures,String,Powershell,Data Structures,我需要将在文件共享中的文件中找到的用户帐户映射到电子邮件地址(以便在以后的步骤中迁移它们) 我就快到了,但我收到的电子邮件地址格式很奇怪,如下所示: @{EmailAddress=第一个。last@xx.xxxxx.com} 如何将其作为常规字符串变量?比如: 首先。last@xx.xxxxx.com“ 我会使用(Get ADUser$createdBy-Properties EmailAddress).EmailAddress或Get ADUser$createdBy-Properties E

我需要将在文件共享中的文件中找到的用户帐户映射到电子邮件地址(以便在以后的步骤中迁移它们)

我就快到了,但我收到的电子邮件地址格式很奇怪,如下所示:

@{EmailAddress=第一个。last@xx.xxxxx.com}

如何将其作为常规字符串变量?比如: 首先。last@xx.xxxxx.com“

我会使用
(Get ADUser$createdBy-Properties EmailAddress).EmailAddress
Get ADUser$createdBy-Properties EmailAddress |选择Object-ExpandProperty EmailAddress
。这些是等价的

“选择对象”将显示一个特性,但即使仅选择一个,它仍将保留为对象的特性。要仅提取属性值,需要指定
-ExpandProperty
参数。但是,执行此操作时,只能指定一个要展开的特性

您还可以真正简化代码。当你已经获得了你所需要的大部分信息时,你在重复你自己

$Files = Get-ChildItem -Path $SourceFilesPath -Force -Recurse

ForEach ($File in $Files)
{

    $createdDate = $File.CreationTime
    $modifiedDate =  $File.LastWriteTime

    $createdBy = $File.GetAccessControl().Owner.Split("\")[-1]

    $email = (Get-ADUser $createdBy -Properties EmailAddress).EmailAddress
    
    Write-host $email
}
另外,您不需要指定
“$($File.Directory)\$($File.Name)”
。您只需指定
$File.FullName

关于Powershell,首先要了解的是一些语言内省

$Files[0]|格式列表-属性*
$Files[0]| fl*
将列出对象的所有属性

$Files[0]| Get Member
$Files[0]| gm
将列出对象的成员函数

$Files[0].GetType().FullName
将列出对象的类型。您可以通过Google搜索并查看对象类的.Net引用

$Files = Get-ChildItem -Path $SourceFilesPath -Force -Recurse

ForEach ($File in $Files)
{

    $createdDate = $File.CreationTime
    $modifiedDate =  $File.LastWriteTime

    $createdBy = $File.GetAccessControl().Owner.Split("\")[-1]

    $email = (Get-ADUser $createdBy -Properties EmailAddress).EmailAddress
    
    Write-host $email
}