我正试图从FIM / MIM中提取数据。我已经能够创建一个收集所有相关用户信息的脚本,然后我将其导出到CSV文件。
当我以交互方式执行脚本(单击.ps1文件或从批处理文件执行.ps1文件)时,一切都运行良好。当我尝试通过计划任务执行脚本时出现问题。它创建文件但文件没有数据。
基于交互式运行与计划任务运行时脚本速度的比较,计划任务花费的时间更少。这让我觉得FIM导出运行错误或无法完成。然后它尝试将空数组的内容导出到.csv文件。
这是我的代码:
set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' " -option constant
set-variable -name CSV -value "C:\Scripts\Script_Output\FIMUsersExport.csv" -option constant
clear
#Add FIMAutomation Snapin if not already loaded
If (@(Get-PSSnapin | Where-Object { $_.Name -eq "FIMAutomation" }).count -eq 0) { Add-PSSnapin FIMAutomation }
#Add FTE filters
$WFDFilter = "/WorkflowDefinition[DisplayName='_Employee Type FTE']"
$curObjectWFD = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($WFDFilter) -ErrorVariable Err -ErrorAction SilentlyContinue
$WFDObjectID = (($curObjectWFD.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "ObjectID" }).value).split(":")[2]
$Filter = "/Person"
$curObject = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($Filter) -ErrorVariable Err -ErrorAction SilentlyContinue
[array]$users = $null
foreach ($Object in $curObject)
{
$ResetPass = New-Object PSObject
$UserDisplayName = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "DisplayName" }).Value)
$UserFirstName = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "FirstName" }).Value)
$UserLastName = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "LastName" }).Value)
$UserEmail = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "Email" }).Value)
$UserMobilePhone = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "msidmOneTimePasswordMobilePhone" }).Value)
$UserPFPosNum = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "pfposNum" }).Value)
$UserPFSupposNum = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "pfsupposNum" }).Value)
$UserOfficePhone = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object { $_.AttributeName -eq "OfficePhone" }).Value)
$ResetPass | Add-Member NoteProperty "DisplayName" $UserDisplayName
$ResetPass | Add-Member NoteProperty "FirstName" $UserFirstName
$ResetPass | Add-Member NoteProperty "LastName" $UserLastName
$ResetPass | Add-Member NoteProperty "Email" $UserEmail
$ResetPass | Add-Member NoteProperty "MobilePhone" $UserMobilePhone
$ResetPass | Add-Member NoteProperty "OfficePhone" $UserOfficePhone
$ResetPass | Add-Member NoteProperty "PFPosNum" $UserPFPosNum
$ResetPass | Add-Member NoteProperty "pfsupposNum" $UserPFSupposNum
$Users += $ResetPass
}
$AHCAUsers = $users | Where-Object{$_.Email -like "*@ahca.myflorida.com"} | Export-Csv -Path $CSV -NoTypeInformation
有什么想法吗?
答案 0 :(得分:0)
我的猜测是计划任务没有足够的权限运行。尝试将其配置为以用户帐户身份运行,以查看是否会产生影响。
您还可以在脚本开头添加Start-Transcript
(并在最后添加Stop-Transcript
),这会将脚本的所有输出记录到文本文件中(包括错误消息),这样您就可以看看它作为计划任务运行时发生了什么。