Script to save and search in xml

 $global:xmlfile = "file.xml"

 $config = @{}

 if(-not (Test-Path $xmlfile)) {
  $config['xmlfile'] = @{}
  $config['xmlfile'] | Export-Clixml $xmlfile
 } else {
 $config['xmlfile'] = Import-Clixml $xmlfile
}

function Set-ConfigItem
{
 param($Key, $Value, $Scope)

 $Key=$Key.Trim()
 $Value=$Value.trim()

 if(-not $Scope -or -not $Key)
 {
  throw 'Scope and key parameters must be provided'
 }
 if($Config[$Scope])
 {
  $Config[$Scope][$Key] = $Value
 }
 else
 {
  throw "Scope not available"
 }
 Write-Config
}

function Get-ConfigItem
{
 param($Key, $Scope)
 $Key=$Key.Trim()
 if(-not $Scope -or -not $Key)
 {
  throw 'Scope and key parameters must be provided'
 }
 if($Config[$Scope])
 {
  $Config[$Scope][$Key]
 }
}

 function Remove-ConfigItem
 {
  param($Key, $Scope)
  if(-not $Scope)
 {
  throw 'Scope must be defined to remove an item.'
 }
 else
 {
  $config[$scope].Remove($Key)
 }
 Write-Config
}

function Get-Config
{
 param($Scope)

 if($Scope)
 {
 $config[$Scope].GetEnumerator() |
 Sort-Object Name
 }
 else
 {
  foreach($scope in $config.GetEnumerator())
  {
    Write-Verbose $scope.Name "scope" -ForegroundColor White -BackgroundColor Green
    $scope.Value.GetEnumerator() | Sort-Object Name
  }
 }
}

function Write-Config
{
 $config['xmlfile'] | Export-Clixml -Path $xmlfile
}

I got this code which is saving the information into text but now I wont to go through a text file and see if any word matchs in the xml file.

file name: My New File Name.doc

I want to search the full name in the xml file. I know that I have a key which is called New File

I wont to bring value for new file key from xml file. How can I do this

Use the Select-XML and Import-Clixml cmdlets for this or the XML .Net name space. It is why they exist. PowerShell by design is XML heavy under the covers.

# get function / cmdlet details
(Get-Command -Name Import-Clixml).Parameters
Get-help -Name Import-Clixml -Full
Get-help -Name Import-Clixml -Online
Get-help -Name Import-Clixml -Examples

(Get-Command -Name Select-Xml).Parameters
Get-help -Name Select-Xml -Full
Get-help -Name Select-Xml -Online
Get-help -Name Select-Xml -Examples

([xml]Xmlfile = Get-Content -Path 'd:\temp\SomeXmlFileName' -Raw)

There are tons of articles and examples all over the web regarding using PowerShell to read / parse create / modify / update XML files. It’s a very common use case. Just do a quick search for ‘PowerShell search XML’, be prepared for a long list.

Also, the Write-Verbose with the color stuff is wrong. That cmdlet will not do that. To do that you’d use Write-Host for colors. Yet unless you really need color, avoid Write-Host. Write-Output is the default, which sends stuff to the screen and is pipeline friendly and you don’t necessarily need to specify that either, unless it’s you coding style or organization coding standards policy.

import-clixml is only for xml created with export-clixml.

import-clixml file.xml   

import-clixml : Element 'Objs' with namespace name 'http://schemas.microsoft.com/powershell/2004/04' was not found. Line 1, position 2.
At line:1 char:1
+ import-clixml file.xml
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Import-Clixml], XmlException
+ FullyQualifiedErrorId : System.Xml.XmlException,Microsoft.PowerShell.Commands.ImportClixmlCommand

Use select-xml or cast a string array to [xml] like this:

$xml = (select-xml / event.xml).node

[xml]$xml = get-content file.xml
$xml.save('file.xml')

Search for a TimeCreated node using Xpath. select-xml (xpath) is case sensitive.

(select-xml //TimeCreated event.xml).node     

SystemTime
----------
2019-01-28T20:43:38.520370900Z

js, but hat is what the OP is actually doing in the post code, in lines 5 -7…

$global:xmlfile = "file.xml"

 $config = @{}

 if(-not (Test-Path $xmlfile)) {
  $config['xmlfile'] = @{}
  $config['xmlfile'] | Export-Clixml $xmlfile
 } else {
 $config['xmlfile'] = Import-Clixml $xmlfile
}

What’s an example key, value, and scope?