PowerShell代码的奇怪行为 - 除非重新启动会话,否则返回错误的结果
我有此代码检查是否存在SSISDB中的项目。在第一次运行中,我确保该项目在那里,并返回正确的值。但是随后我删除项目并再次运行代码,但然后再次返回1。当我重新启动会话时,它开始再次返回正确的答案。问题是什么,我该如何解决?
import-module sqlserver;
$TargetInstanceName = "localhost\default"
$TargetFolderName = "FolderForTesting";
$ProjectName = "ProjectTesting";
$catalog = Get-Item SQLSERVER:\SSIS\$TargetInstanceName\Catalogs\SSISDB\
$folder = $catalog.Folders["$TargetFolderName"];
$project = $folder.Projects["$ProjectName"];
if($null -eq $project){
Return 0
} else {
Return 1
}
I have this code which check for the existence of a project in SSISDB. On the first run I make sure the project is there and it returns the correct value. But then I delete the project and run the code again but it then returns 1 again. When I restart the session then it starts to return the correct answer again. What is the problem and how can I solve it?
import-module sqlserver;
$TargetInstanceName = "localhost\default"
$TargetFolderName = "FolderForTesting";
$ProjectName = "ProjectTesting";
$catalog = Get-Item SQLSERVER:\SSIS\$TargetInstanceName\Catalogs\SSISDB\
$folder = $catalog.Folders["$TargetFolderName"];
$project = $folder.Projects["$ProjectName"];
if($null -eq $project){
Return 0
} else {
Return 1
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结合我的和 theo 对可能的解决方案的有用评论:
这是基于刷新SQL Server PowerShell提供商和 ps + sqlps'> ps + sqlps刷新SQL Server对象和您自己的测试。我找不到有关该主题的任何官方信息。
Combining mine and Theo's helpful comments into a possible solution:
This is based on Refreshing the SQL Server PowerShell Provider and PS + SQLPS refreshing the SQL Server object and your own testing. I couldn't find any official information regarding the topic.