Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
Sql server Powershell基于联接输出两个阵列的内容_Sql Server_Powershell_Csv - Fatal编程技术网

Sql server Powershell基于联接输出两个阵列的内容

Sql server Powershell基于联接输出两个阵列的内容,sql-server,powershell,csv,Sql Server,Powershell,Csv,我正在查询sql以从SharePoint nintex数据库收集一些nintex信息。Nintex仅持有SharePoint站点ID。因此,我需要powershell从sql输出的结果中获取url和一些附加数据 我可以使用以下方法进行此操作: $GUIDS = ($DS.Tables[0] | select -ExpandProperty siteid) | Format-Table -HideTableHeaders | Out-String foreach($line in $guids)

我正在查询sql以从SharePoint nintex数据库收集一些nintex信息。Nintex仅持有SharePoint站点ID。因此,我需要powershell从sql输出的结果中获取url和一些附加数据 我可以使用以下方法进行此操作:

$GUIDS = ($DS.Tables[0] | select -ExpandProperty  siteid) | Format-Table -HideTableHeaders | Out-String
foreach($line in $guids)
{Get-Spsite -identity $line  | Select -property ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation }
但是我还需要csv输出,以包括我在数组$workflowdetails中拥有的workflowinitiator、workflowname和activityname

如何将输出合并为一个并导出到csv 这就是我到目前为止所做的:

[CmdletBinding()]

param
(
[Parameter(Mandatory=$True)]
 [string]$SQLServerInstance,
[Parameter(Mandatory=$True)]
[string]$NintexConfigDBName
)
Add-PSSnapin Microsoft.SharePoint.PowerShell
$ConnectionTimeout = 30
$Query =  "SELECT DISTINCT i.workflowname,i.siteid,i.workflowinitiator, a.activityname FROM dbo.workflowinstance 
i inner join WorkflowProgress P on I.InstanceID=P.InstanceID inner join Activities A on P.ActivityID=A.ActivityID WHERE a.activityname IN ('Call web service','Execute SQL','Query LDAP','Query XML', 'Start workflow in Nintex Workflow Cloud ',  'Update XML  ', 'Web request ', 'Capture document set version  ', 'Copy to file share',  'Create list', 'Declare as record ', 'Delete drafts', 'Delete item ', 'Delete multiple items', 'Delete previous versions', 'Discard check out ','Query list','Send document set to repository',  'Send document to repository','Set approval status ','Set item permissions', 'Undeclare as record  ', 'Update multiple items', 'Action set', 'Commit pending changes', 'Run parallel actions', 'State machine ', 'Pause for...  ', 'Pause until...  ', 'Wait for check out status change ', 'Wait for item update ', 'Create site  ','Create site collection','Decommission site collection ',  'Delete site', 'Publish Workflow', 'Assign Flexi task', 'Complete workflow task ' ) "

$QueryTimeout = 120

$conn=new-object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server={0};database={1};Integrated Security=True;Connect Timeout={2}" -f $SQLServerInstance,$NintexConfigDBName,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()
$cmd=new-object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
$da.fill($ds)
$conn.Close()
$DS.Tables[0]  
$workflowdetails = ($DS.Tables[0] | select -ExpandProperty  siteid, workflowinitiator, workflowname,activityname ) | Format-Table -HideTableHeaders | Out-String
$GUIDS = ($DS.Tables[0] | select -ExpandProperty  siteid) | Format-Table -HideTableHeaders | Out-String
foreach($line in $guids)
{Get-Spsite -identity $line  | Select -property ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation }

如果要将所有站点导出到同一个CSV文件,只需在循环后使用导出CSV:

因此,我们:

foreach ($line in $guids) {
    Get-Spsite -identity $line
} | Select ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation
与此相反:

foreach ($line in $guids) {
    Get-Spsite -identity $line | Select -property ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation
}
如果要将站点数据和SQL结果结合起来,基本上必须创建某种方法,在输出另一项数据的同时查找其中一项数据

哈希表的设计目的是通过一个键快速查找内容,因此将所有站点存储在哈希表中是有意义的:

$sitesById = @{}
foreach ($SiteID in $DS.Tables[0].SiteID) {
    $sitesById[$SiteID] = Get-Spsite -identity $SiteID
}
之后,您可以使用带有计算列的Select Object将SharePoint网站中的数据添加到SQL输出

$DS.Tables[0] |
    Select-Object siteid, workflowinitiator, workflowname, activityname,
        @{name="URL"; expression={ $sitesById[$_.siteid].URL }}
        @{name="Owner"; expression={ $sitesById[$_.siteid].Owner }},
        @{name="Hostname"; expression={ $sitesById[$_.siteid].Hostname }} |
    Export-Csv -Path c:\temp\url.csv -NoTypeInformation

如果要将所有站点导出到同一个CSV文件,只需在循环后使用导出CSV:

因此,我们:

foreach ($line in $guids) {
    Get-Spsite -identity $line
} | Select ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation
与此相反:

foreach ($line in $guids) {
    Get-Spsite -identity $line | Select -property ID, URL, OWner, Hostname | Export-Csv -Path c:\temp\url.csv -NoTypeInformation
}
如果要将站点数据和SQL结果结合起来,基本上必须创建某种方法,在输出另一项数据的同时查找其中一项数据

哈希表的设计目的是通过一个键快速查找内容,因此将所有站点存储在哈希表中是有意义的:

$sitesById = @{}
foreach ($SiteID in $DS.Tables[0].SiteID) {
    $sitesById[$SiteID] = Get-Spsite -identity $SiteID
}
之后,您可以使用带有计算列的Select Object将SharePoint网站中的数据添加到SQL输出

$DS.Tables[0] |
    Select-Object siteid, workflowinitiator, workflowname, activityname,
        @{name="URL"; expression={ $sitesById[$_.siteid].URL }}
        @{name="Owner"; expression={ $sitesById[$_.siteid].Owner }},
        @{name="Hostname"; expression={ $sitesById[$_.siteid].Hostname }} |
    Export-Csv -Path c:\temp\url.csv -NoTypeInformation

您可以使用-append和-Force参数将$workflowdetails附加到url.csv。类似于此-$workflowdetails | export csv-Path c:\temp\url.csv-NoTypeInformation-Append-Force您可以使用-Append和-Force参数将$workflowdetails附加到url.csv。类似这样的内容-$workflowdetails | export csv-Path c:\temp\url.csv-NoTypeInformation-Append-force非常感谢您的支持。我现在明白了。。我这样做了,它现在起作用了如果这对你有帮助,请投赞成票。谢谢你,这帮助了我这个网站。非常感谢你Tonalak。我现在明白了。。我这样做了,它现在起作用了如果这对你有帮助,请投赞成票。谢谢你,这帮助了我这个网站。