控制台 table 输出 -> csv 文件 - Export-csv
Console table output -> csv file - Export-csv
我通过 "Displayname, name and Type" 在控制台中列出了所有 "User Profile Properties" 有没有一种简单的方法可以将控制台中的 table 输出导出到 csv 文件?
这可能是一个以前被问过很多次的问题,但我找不到好的方法来做这个。
在控制台中捕获输出。
脚本
###############################################################################
# Export user profile properties to csv
###############################################################################
. .\Environment.ps1
Write-Host "Retrieving User Profile Properties with $DomainUser at $FinalMySiteURL" -ForegroundColor Cyan
[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server");
$site=new-object Microsoft.SharePoint.SPSite("$FinalMySiteURL");
$serviceContext = Get-SPServiceContext $site;
$site.Dispose();
Write-Host "Getting user profile manager ..." -NoNewline
Try
{
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
Write-Host "Done" -ForegroundColor Green
}
Catch [system.exception]
{
Write-Host "Error loading file, add $DomainUser as admin to the user profile service (admin/privillage)" -ForegroundColor Red
Break
}
$userProfile = $upm.GetUserProfile("$DomainUser");
$userProfileProperties = $userProfile.Properties | sort DisplayName | FT DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
$userProfileProperties
Write-Host "Export to output to csv file ..." -NoNewline
Try
{
$userProfileProperties | Export-Csv $scriptPath\UserProfileProperties.csv
Write-Host "Done" -ForegroundColor Green
}
Catch [system.exception]
{
Write-Host "Error loading file, add $DomainUser as admin to the user profile service (admin/privillage)" -ForegroundColor Red
Break
}
尝试将格式 Table (FT) 更改为 Select 语句...
所以这样:
$userProfileProperties = $userProfile.Properties | sort DisplayName | FT DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
变成:
$userProfileProperties = $userProfile.Properties | sort DisplayName | select DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
我通过 "Displayname, name and Type" 在控制台中列出了所有 "User Profile Properties" 有没有一种简单的方法可以将控制台中的 table 输出导出到 csv 文件?
这可能是一个以前被问过很多次的问题,但我找不到好的方法来做这个。
在控制台中捕获输出。
脚本
###############################################################################
# Export user profile properties to csv
###############################################################################
. .\Environment.ps1
Write-Host "Retrieving User Profile Properties with $DomainUser at $FinalMySiteURL" -ForegroundColor Cyan
[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server");
$site=new-object Microsoft.SharePoint.SPSite("$FinalMySiteURL");
$serviceContext = Get-SPServiceContext $site;
$site.Dispose();
Write-Host "Getting user profile manager ..." -NoNewline
Try
{
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
Write-Host "Done" -ForegroundColor Green
}
Catch [system.exception]
{
Write-Host "Error loading file, add $DomainUser as admin to the user profile service (admin/privillage)" -ForegroundColor Red
Break
}
$userProfile = $upm.GetUserProfile("$DomainUser");
$userProfileProperties = $userProfile.Properties | sort DisplayName | FT DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
$userProfileProperties
Write-Host "Export to output to csv file ..." -NoNewline
Try
{
$userProfileProperties | Export-Csv $scriptPath\UserProfileProperties.csv
Write-Host "Done" -ForegroundColor Green
}
Catch [system.exception]
{
Write-Host "Error loading file, add $DomainUser as admin to the user profile service (admin/privillage)" -ForegroundColor Red
Break
}
尝试将格式 Table (FT) 更改为 Select 语句...
所以这样:
$userProfileProperties = $userProfile.Properties | sort DisplayName | FT DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
变成:
$userProfileProperties = $userProfile.Properties | sort DisplayName | select DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}