Powershell 在一个参数中设置多个值

Powershell 在一个参数中设置多个值,powershell,Powershell,我编写了以下脚本来比较保存在文件夹中的作业,并在服务器上按名称进行比较 $submaporiginal = 'D:\Jobs_from_Server\TEST_Jobs_Aangepast' $SqlServer1Name = "servername" $SqlServer1 = New-Object Microsoft.SqlServer.Management.Smo.Server($SqlServer1Name) $files = Get-ChildItem $submaporigin

我编写了以下脚本来比较保存在文件夹中的作业,并在服务器上按名称进行比较

$submaporiginal = 'D:\Jobs_from_Server\TEST_Jobs_Aangepast'

$SqlServer1Name = "servername"

$SqlServer1 = New-Object Microsoft.SqlServer.Management.Smo.Server($SqlServer1Name)

$files = Get-ChildItem $submaporiginal *.sql 

$SqlServer1JobListing = $SqlServer1.JobServer.Jobs | 
    Select-Object -ExpandProperty Name

foreach ($file in $files) 
    {
    $stap1 =  $file.Name  
    $locatiedtsx = $stap1.IndexOf("_goed")
    $SqlServer2JobListing = $stap1.Substring(0,$locatiedtsx)
    }

Compare-Object $SqlServer1JobListing $SqlServer2JobListing 
    {
    if ($_.SideIndicator -eq "<=") 
        {Write-Host $_}
    } 
$submaroriginal='D:\Jobs\u from\u Server\TEST\u Jobs\u aangepass'
$SqlServer1Name=“servername”
$SqlServer1=新对象Microsoft.SqlServer.Management.Smo.Server($SqlServer1Name)
$files=Get ChildItem$submaroriginal*.sql
$SqlServer1JobListing=$SqlServer1.JobServer.Jobs |
选择对象-属性名称
foreach($files中的文件)
{
$stap1=$file.Name
$locatiedtsx=$stap1.IndexOf(“\u goed”)
$SqlServer2JobListing=$stap1.Substring(0,$locatiedtsx)
}
比较对象$SqlServer1JobListing$SqlServer2JobListing
{

如果($.SideIndicator-eq“您的问题是您总是重新分配
$SqlServer2JobListing
变量,那么您需要向数组或列表中添加一个值。如下所示:

$SqlServer1JobListing = New-Object System.Collections.ArrayList
foreach ($file in $files) 
{
    $stap1 =  $file.Name  
    $locatiedtsx = $stap1.IndexOf("_goed")
    $SqlServer1JobListing.Add($stap1.Substring(0,$locatiedtsx))
}

这样,在您的
foreach
循环之后,您将获得所有项的集合,而不是像以前那样只获得最后一个项。

您的问题是,您总是重新分配
$SqlServer2JobListing
变量,而需要向数组或列表添加一个值。如下所示:

$SqlServer1JobListing = New-Object System.Collections.ArrayList
foreach ($file in $files) 
{
    $stap1 =  $file.Name  
    $locatiedtsx = $stap1.IndexOf("_goed")
    $SqlServer1JobListing.Add($stap1.Substring(0,$locatiedtsx))
}

这样,在您的
foreach
循环之后,您将获得所有项目的集合,而不是像以前那样只显示最后一个项目。

Hi代码工作得很好,但显示的是一个匹配的列表,而不是一个不匹配的包列表。Hi代码工作得很好,但显示的是一个匹配的列表,而不是一个不匹配的包列表帽子不相配。