Write and search if a value already exist.


I’m extracting some fields from an XML…


The $UUID is unique, so, i want to save that field in a TXT, and then, search in that same TXT if the value already exist.

If the value exist, just ignore it and process the next XML.

$filepath = "C:\UUIDs.txt"
$uuids = Get-Content C:\UUIDs.txt

ForEach ($uuid in $uuids) {
  If ($uuid -eq $uuids) {
    Write-Output 'Already exist.'
   #Do the XML creation...
   write-output ($uuid) | out-file -filepath $filepath -encoding ascii -append

If you created an array of UUIDs from your file you can check with

$UUID -contains $UUIDArray
if the new UUID is already there.


I think i got it.

What do you think?

$Saved = Get-Content C:\CC\Saved.txt
$LogRepeated = "C:\CC\LogRepeated.txt"
$LogSaved = "C:\CC\Saved.txt"
$uuid = "1234"

  If ($Saved -contains $uuid)
    Write-Output "File Already exist."
    Write-Output ($uuid) | Out-File -FilePath $LogRepeated -Encoding ASCII -Append
   #XML Generator Code
   Write-Output "File added."
   Write-Output ($uuid) | Out-File -FilePath $LogSaved -Encoding ASCII -Append