我正在尝试源代码,控制我的Schedules &将其安排为.json文件,并使用dbatools SQL代理命令套件部署它们。
给定以下表格的$sa = Get-Credential和foo.config ..。
{
"Schedule": "Foo",
"Disabled": false,
"FrequencyType": "Weekly",
"FrequencyInterval": "EveryDay",
"FrequencySubdayType": "Time",
"FrequencySubdayInterval": 0,
"FrequencyRelativeInterval": "Unused",
"FrequencyRecurrenceFactor": 1,
"StartDate": "20180823",
"EndDate": "20181023",
"StartTime": "070000",
"EndTime": "235959"
}试图在解决方案使用以下消息失败基本解析中使用C6:
~> $foo = Get-Content foo.config | ConvertFrom-Json
~> New-DbaAgentSchedule @foo -ServerInstance "." -SqlCredential $sa警告:没有提供时间表!请提供时间表名称。
那太糟糕了..。尤其是既然下面的工作还不错..。
$bar = @{
Schedule= "Foo"
Disabled= $false
FrequencyType= "Weekly"
FrequencyInterval= "EveryDay"
FrequencySubdayType= "Time"
FrequencySubdayInterval= 0
FrequencyRelativeInterval= "Unused"
FrequencyRecurrenceFactor= 1
StartDate= "20180823"
EndDate= "20181023"
StartTime= "070000"
EndTime= "235959"
}
New-DbaAgentSchedule @bar -ServerInstance "." -SqlCredential $sa我真的不想麻烦地键入每个单独的... -Param1 $foo.Param1 -Param2 $foo.Param2 ...,因为我很懒。我非常希望将我的配置文件飞溅到各种命令中。为什么这个不能工作!
发布于 2018-10-10 21:52:08
您可以做的一件事是,当您从json转换到实际将其转换为you...so时,有一个选项,它可以保存几行代码。
(Get-Content C:\temp\foo.config | ConvertFrom-Json).GetType()
<#
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PSCustomObject System.Object
#>
(Get-Content C:\temp\foo.config | ConvertFrom-Json -AsHashtable).GetType()
<#
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
#>我没有任何可访问的服务器可以确认,但是第二个命令的输出显示它是名称/值格式:
Name Value
---- -----
EndTime 235959
StartDate 20180823
FrequencySubdayInterval 0
FrequencyType Weekly
Schedule Foo
Disabled False
FrequencyRelativeInterval Unused
EndDate 20181023
FrequencySubdayType Time
FrequencyInterval EveryDay
StartTime 070000
FrequencyRecurrenceFactor 1由于以上所述只能在PowerShell Core6.1上工作(通常现在可用),您将需要使用WindowsCompatibility模块来使用PS中的dbatools。您可以使用PS Core中的以下代码来完成此操作:
Install-Module WindowsCompatibility
Import-WinModule dbatools第二个命令利用WinRm来支持隐式远程处理。上述情况意味着您已经在Windows上安装了PowerShell Core。文档显示了如何在需要时对远程计算机执行此操作。
在那里,您可以根据需要运行dbatools命令:

发布于 2018-10-10 15:25:36
4小时前赛尔夫..。如果你费心检查$foo和$bar的类型,你可能不会浪费一整个下午在你的开放式办公室平面图上大声咒骂,因为你翻阅这些文档毫无结果.
~> ($foo | Get-Member).TypeName[0]
System.Management.Automation.PSCustomObject
~> ($bar | Get-Member).TypeName[0]
System.Collections.Hashtable甚至还有这个问答网络上的一种方便的广义解将PSCustomObject转换为HashTable。
$foo.psobject.properties | foreach -begin {
$foo=@{}
} -process {
$foo."$($_.Name)" = $_.Value
} -end {$foo}
~> New-DbaAgentSchedule @foo -ServerInstance "." -SqlCredential $sa简单的小吃,柠檬的挤压。
你个疯狂的家伙。当你觉得自己很蠢的时候,不妨在网上分享一下解决办法,以防它对别人有帮助。如果你觉得自己非常主动,也许可以考虑留出一些时间去做对模块作出贡献。
https://dba.stackexchange.com/questions/219777
复制相似问题