sql-server - 如何附加到powershell哈希表值?

标签 sql-server powershell hashtable smo

我正在通过 Microsoft.SqlServer.Management.Smo.Server 对象列表进行交互,并将它们添加到哈希表中,如下所示:

$instances = Get-Content -Path .\Instances.txt
$scripts = @{}

foreach ($i in $instances)
{
    $instance = New-Object Microsoft.SqlServer.Management.Smo.Server $i
    foreach($login in $instance.Logins)
    {
        $scripts.Add($instance.Name, $login.Script())       
    }
}

到目前为止一切顺利。我现在想做的是将一个字符串附加到哈希表值的末尾。因此,对于 $instance,我想将一个字符串附加到该 $instance 的哈希表值中。我该怎么做呢?我已经开始这样做,但我不确定我是否走在正确的道路上:

foreach ($db in $instance.Databases)
{       
    foreach ($luser in $db.Users)
    {
        if(!$luser.IsSystemObject)
        {
            $scripts.Set_Item ($instance, <what do I add in here?>)
        }
    }
}

干杯

最佳答案

$h= @{}

$h.add("Test", "Item")
$h

Name                           Value                                                                                                                                                   
----                           -----                                                                                                                                                   
Test                           Item                                                                                                                                                    

$h."Test" += " is changed"
$h

Name                           Value                                                                                                                                                   
----                           -----                                                                                                                                                   
Test                           Item is changed                                                                                                                                         

关于sql-server - 如何附加到powershell哈希表值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396771/

相关文章:

c# - 调用存储过程不返回任何内容

python - powershell tts 命令旁白使用 python 更改

Powershell 中 AppAnnie 的 "Bearer"身份验证的 RESTful API 请求

powershell - 为什么 PowerShell 间歇性找不到 List[string].Add() 方法?

java - Java Hashtable 中的 Set keys() 和 Set keyset() 有什么区别?

创建具有快速插入、删除、成员资格测试和随机选择的数据结构

sql - 如何在sql脚本中设置CHECK_POLICY OFF

sql-server - SQL Server 中覆盖和单个索引的重叠

sql - 是否可以在 where 条件下使用列元组?

powershell - 将输入哈希表中的键添加到输出哈希表