我正在开发一个脚本,用于使用PnP在SharePoint中创建导航。为此,我用我的URLS和一些其他信息创建了一个CSV。
我的CSV如下所示:
Name,ParentName,Level,URL,Status,Order
Tools,Consulting,1,http://linkless.header/,Existing,3
Tool Wiki,Tools,2,http://linkless.header/,Existing,3
Tool Box,Tools,2,http://linkless.header/,add,2
Tool Development,Tools,2,https://linkless.header/,Remove,1
我使用以下命令导入CSV
$CURRENT_DIRECTORY=Get-Location
$CSV_Navigation = Import-Csv $CURRENT_DIRECTORY\UrlsNavigation.csv
然后我要进行一些更改,然后再次将其导出。
$STATUS_ADD="Add"
$STATUS_REMOVE="Remove"
$STATUS_EXISTING="Existing"
function setStatusInCSV {
ForEach($Item in $CSV_Navigation) {
If ($Item.Status -eq $STATUS_ADD) {
$Item.Status = $STATUS_EXISTING
}
}
Export-Csv $CSV_Navigation -Path $CURRENT_DIRECTORY\UrlsNavigation.csv -NoTypeInformation
}
为此,我收到以下错误
Export-Csv : Cannot convert 'System.Object[]' to the type 'System.Char' required by parameter 'Delimiter'. Specified method is not supported.
At Path\Navigation\UpdateNavigation.ps1:95 char:16
+ Export-Csv $CSV_Navigation -Path $CURRENT_DIRECTORY\UrlsNavigatio ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ExportCsvCommand
如果我使用定界符运行命令,则它看起来像这样:
Export-Csv : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At Path\Navigation\UpdateNavigation.ps1:95 char:5
+ Export-Csv $CSV_Navigation -Path $CURRENT_DIRECTORY\UrlsNavigatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
我的$ CSV_Navigation看起来像这样
Write-Host $CSV_Navigation
@{Name=Tools; ParentName=Consulting; Level=1; URL=http://linkless.header/; Status=Ex
isting; Order=3} @{Name=Tool Wiki; ParentName=Tools; Level=2; URL=http://linkless.header/; Status=Existing; Order=3} @{Name=Tool Box; ParentName=Tools; Level=2; URL=http://linkless.header/; Status=Existing; Order=2} @{Name=Tool Development; ParentName=Tools; Leve
l=2; URL=https://linkless.header/; Status=Remove; Order=1}
答案 0 :(得分:2)
我认为这里的问题是该命令的位置参数。
您需要定义您的输入objetc是什么。像这样:
Export-Csv -InputObject $CSV_Navigation -Path $CURRENT_DIRECTORY\UrlsNavigation.csv -NoTypeInformation
编辑:您需要使用Select-Object -Property YourPropeerties
来获得正确的输出或将数组通过管道传递给命令:
$CSV_Navigation | Export-Csv -Path $CURRENT_DIRECTORY\UrlsNavigation.csv -NoTypeInformation