powershell - SSIS 和 Powershell 文件锁
问题描述
我正在使用 SSIS 和 Powershell 来检查文件是否被锁定。
我在一个名为“Cmd”的变量中有以下表达式:
"-NoProfile -ExecutionPolicy ByPass -Command \"try { [IO.File]::OpenWrite(‘” + @[User::TestFilePath] + “‘).close();0 } catch {999}"
评估结果如下:
-NoProfile -ExecutionPolicy ByPass -Command "try { [IO.File]::OpenWrite(‘” + @[User::TestFilePath] + “‘).close();0 } catch {999}
使用 Execute Process Task 我然后调用上面的 Cmd 变量并在其后有成功和失败约束。进程总是报告成功,即使我打开有问题的文件,重命名甚至删除它。
如果我随后修改以下内容,任务将始终失败,即使它没有打开:
"-NoProfile -ExecutionPolicy ByPass -Command \"try { [IO.File]::OpenWrite(‘” + @[User::TestFilePath] + “‘).close();exit 0} catch {exit 999}"
我错过了什么?
解决方案
如果它对任何人有帮助,我找到了解决方案。我没有通过表达式调用 PS 脚本,而是通过 Process Task 在 PS 文件中调用了实际的 PS 文件:
$file = "\\xxxx\xxxxx\xxxxxxxx\test.log"
try { [IO.File]::OpenWrite($file).close();exit 0 } catch { exit 999}
推荐阅读
- json - 无法通过 res.json 发送 JSON 数据
- java - 为什么我不能构建 apk 而不是 aar?
- flutter-layout - 是否可以在 Flutter 中连续放置一列?
- kotlin - 如何在 Kotlin 中进行方法检测 - 但保持方法可测试
- algorithm - 为什么这个内部循环执行 n + 1 次?
- azure - 针对 Azure AD 进行身份验证
- yaml - 如何从 yaml 数据文件中以 JSON+LD 格式输出社交网址?
- angular - 在角度路由中从堆栈中删除以前的页面
- html - 绝对定位的 div 中的 SVG 图像在 Firefox 上与 Chrome 不同
- python - 计算和绘制分割掩码像素