Need powershell script

This topic contains 1 reply, has 2 voices, and was last updated by  Lev Leiderman 2 weeks, 2 days ago.

  • Author
    Posts
  • #97735

    GaneshRaj
    Participant

    Need a powershell code to remove the list of servers in first file based on the second file details. The second file contains the list of the server details that needs to be removed in the first file. Both the files will be in CSV format. As I am new to scripting please edit the script and provide the same.
    Error "Method invocation failed because [System.Management.Automation.PSCustomObject] doesn't contain a method named 'IndexOf'".
    As Iam new to scripting please reframe the script and provide it.

    $serverlist_csv1 = Import-Csv -Path $file1
    $serverlist_temp1 = $serverlist_csv1
    $exclude_serverlist_csv = Import-Csv -Path $file2
    foreach ($server in $exclude_serverlist_csv) {
    $servers1 = ($serverlist_csv1.'SourceHostName' | Select-Object -ExcludeProperty 'SourceHostName')

    if ($servers1 -contains $server.'Exclude Server') {
    $server_object1 = ($serverlist_csv1 | Where-Object {$_.SourceHostName -eq $server.'Exclude Server'})

    $serverindex1 = $serverlist_csv1.IndexOf($server_object1)
    $dataResizable1 = {$serverlist_csv1}.Invoke()
    $dataResizable1.RemoveAt($serverindex1)
    $serverlist_csv1 = $dataResizable1
    }
    }

  • #97737

    Lev Leiderman
    Participant

    Hi,
    which columns and headers do you have in your csv files?

    also, please try to run each line in a time, to figureout when the problem is occurred.

    this is the first step for troubleshoot...

You must be logged in to reply to this topic.