小编use*_*704的帖子

使用powershell获取短路径

我试图使用PowerShell中的以下代码获取短路径.对于某些文件夹,它可以工 对某些人来说,它不起作用.

$a = New-Object -ComObject Scripting.FileSystemObject 
$f = $a.GetFile("C:\Program Files\Internet Explorer") 
$f.ShortPath
Run Code Online (Sandbox Code Playgroud)

虽然文件夹可用,但我收到以下错误:

Exception calling "GetFile" with "1" argument(s): "Exception from HRESULT: 0x800A0035 (CTL_E_FILENOTFOUND)"
At C:\Misc\GetShortPath.ps1:4 char:1
+ $f = $a.GetFile("C:\Program Files\Internet Explorer")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation
Run Code Online (Sandbox Code Playgroud)

有人可以请帮助

powershell

3
推荐指数
1
解决办法
1179
查看次数

如何将参数传递到Powershell脚本并在远程计算机上运行

我试图将2个参数传递给PS脚本,该脚本将修补远程计算机上的SQL Server。这是我使用的代码:

$Patcher = "\\remoteShareLocation\SQLpatcher.ps1"
$ver = "SQL2012"
$inst = "NEWINST"

Invoke-Command -ComputerName RMTMACHINE -credential dmn\usrname -ScriptBlock {$Patcher $ver $inst}
Run Code Online (Sandbox Code Playgroud)

这会要求提供凭据,但不会运行,也不会显示任何输出。语法有什么问题吗?还有其他替代cmdlet吗?

powershell remote-execution

0
推荐指数
1
解决办法
2362
查看次数

标签 统计

powershell ×2

remote-execution ×1