Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在文本中查找并创建一个警告窗口_Powershell_Search_Ini - Fatal编程技术网

Powershell 在文本中查找并创建一个警告窗口

Powershell 在文本中查找并创建一个警告窗口,powershell,search,ini,Powershell,Search,Ini,我想在INI文件的文本中搜索类似C:\example\example的路径。当它找到这样一个路径时,我希望屏幕上显示一个带有警告的消息框。INI文件位于文件夹及其子文件夹中 我试过了,但失败了 $PathOfFolderAndSubfolder = C:\example\example\* if ((Get-ChildItem -Path $PathOfFolderAndSubfolder -Filder \*/) -eq $true) { [System.Windows.Forms.M

我想在INI文件的文本中搜索类似C:\example\example的路径。当它找到这样一个路径时,我希望屏幕上显示一个带有警告的消息框。INI文件位于文件夹及其子文件夹中

我试过了,但失败了

$PathOfFolderAndSubfolder = C:\example\example\*
if ((Get-ChildItem -Path $PathOfFolderAndSubfolder -Filder \*/) -eq $true) {
    [System.Windows.Forms.MessageBox]::Show("error", "error", 0)
}
Get ChildItem用于枚举容器的子项,例如目录中的文件,而不是列出文件的内容。对后者使用“获取内容”:

$filename = 'C:\path\to\some.ini'
$pattern  = 'C:\example\example'

if ((Get-Content $filename) -like "*${pattern}*") {
    [Windows.Forms.MessageBox]::Show("error", "error", 0)
}
如果要检查特定文件夹子树中的每个INI文件,则需要递归到该文件夹并检查每个匹配文件,例如:

$basedir  = 'C:\some\folder'
$filename = 'C:\path\to\some.ini'
$pattern  = 'C:\example\example'

$found = Get-ChildItem $basedir -Include '*.ini' -Recurse |
         Where-Object { (Get-Content $_.FullName) -like "*${pattern}*" }

if ($found) {
    [Windows.Forms.MessageBox]::Show("error", "error", 0)
}

这完全没有道理。你能把你的问题改一下吗?代码中的ini文件在哪里?请张贴您收到的错误。并检查您的代码过滤器中的拼写是否正确?。并将$PathFolderandSubfolder的值括在quotesthanks中。有没有办法在消息框中设置ini文件的第h部分的错误?$found | Select Object-Expand FullName-join`r`n