I need some help with a batch script to recursively find the folder a particular file is in. I have the below PowerShell script which works perfectly fine but I can't get it to run due to execution policy hence I was wondering if anyone can help me convert it to batch file please?
$val = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{785A2E83-C8B2-46BB-8839-514DE2243EAD}' -Name "DisplayName" -ErrorAction silentlycontinue
if($val.DisplayName -ne 'Internet Explorer 11') {
$ccmIE11Folders = @(Get-ChildItem -Path C:\Windows\ccmcache -Filter IE11-Setup-Full.msi -Recurse)
If($ccmIE11Folders.count -gt 0) {
& "$($ccmIE11Folders[0].DirectoryName)\Install.cmd"
}
}
The script first looks for a registry item property. If it does not exist then it recursively finds the file "IE11-Setup-Full.msi" under C:\Windows\CCMCache folder. If found it runs Install.cmd from that resultant folder.
If you wanted to know, we are deploying IE11 in the enterprise using SCCM however a small percentage of them are failing for some unknown reason so I am trying to re-run the installer using this script.
Thanks in advance.
答案 0 :(得分:0)
另一种方法是更改PS脚本,使其符合现行的执行策略。你可以签署脚本。
或者,如果脚本实际上不是远程的,您可以在执行点本地重新创建脚本。如果脚本已经本地存储在将要执行它的计算机上,但它仍然被认为是远程的,那么它很可能是从另一台计算机复制的。
当我遇到这个时,我用记事本创建了一个新的空.ps1文件,用记事本打开旧脚本,将整个事件复制到剪贴板并粘贴到新文件中。普雷斯托!新文件不再是“远程”。祝你好运。
答案 1 :(得分:0)
您可以在调用之前取消阻止cmd文件,从而有效地重置其中的标记ADS:
If ($ccmIE11Folders.count -gt 0) {
$cmd = "$($ccmIE11Folders[0].DirectoryName)\Install.cmd"
Unblock-File $cmd
& $cmd
}