需要New-Object -comObject帮助 [英] New-Object -comObject Help Needed

查看:118
本文介绍了需要New-Object -comObject帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动执行右键单击网络文件夹并选择"始终可以脱机使用"的过程。  所以我在网上搜索并找到了使用PowerShell执行此操作的方法。  

I need to automate the process of right-click a network folder and selecting "Always Available Offline".   So I searched online and found a way to use PowerShell to do this.  

 $o = New-Object -ComObject Shell.Application
        $o.Namespace("H:\").Self.verbs() |
        Where-Object { $_.Name -eq 'Always &available offline' } |
        ForEach-Object { $_.DoIt() } 

这是我发现的,当我在我的电脑上测试代码时,它按预期工作。  我确信它会在全球范围内发挥作用。  我使用与我的笔记本电脑相同的构建脚本构建了一个测试盒,当我在新建的
PC上测试此代码时,它确实不行。  任何人都有任何想法,为什么这将在一台PC上工作,而不是另一台?  我想我的PC上运行的服务没有在测试PC上运行。  任何人都有任何想法?

This is what I found and when i tested the code on my PC, it worked as expected.  I was convinced it would work globally.  I built out a test box using the same build scripts as my laptop and sure enough when I tested this code on the newly built PC, it did not work.  ANyone have any ideas as to why this will work on one PC, but not another?  I imagine a service is running on my PC that is not running on the test PC.  Anyone have any ideas?

谢谢。  

Thanks.  

Matt Dillon

Matt Dillon

推荐答案

Hi Matt,

Hi Matt,

您是否在测试PC上设置执行策略以允许脚本运行?

Did you set the execution policy on the test PC to allow the script to run?


这篇关于需要New-Object -comObject帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆