I can't seem to get individual elements when comparing 2 arrays using Compare-Object

My backup software keeps track of servers with issues using a 30 day rolling log, which it emails to me once a week in CSV format. What I want to do is create a master list of servers, then compare that master list against the new weekly lists to identify
servers that are not in the master list, and vice versa. That way I know what servers are new problem and which ones are pre-existing and which ones dropped off the master list. At the bottom is the entire code for the project. I know it's a bit much
but I want to provide all the information, hopefully making it easier for you to help me :)
Right now the part I am working on is in the Compare-NewAgainstMaster function, beginning on line 93. After putting one more (fake) server in the master file, the output I get looks like this
Total entries (arrMasterServers): 245
Total entries (arrNewServers): 244
Comparing new against master
There are 1 differences.
InputObject SideIndicator
@{Agent= Virtual Server in vCenterServer; Backupse... <=
What I am trying to get is just the name of the server, which should be $arrDifferent[0] or possibly $arrDifferent.Client. Once I have the name(s) of the servers that are different, then I can do stuff with that. So either I am not accessing the array
right, building the array right, or using Compare-Object correctly.
Thank you!
Sample opening lines from the report
" CommCells > myComCellServer (Reports) >"
" myComCellServer -"
" 30 day SLA"
CommCell Details
" Client"," Agent"," Instance"," Backupset"," Subclient"," Reason"," Last Job Id"," Last Job End"," Last Job Status"
" myServerA"," vCenterServer"," VMware"," defaultBackupSet"," default"," No Job within SLA Period"," 496223"," Nov 17, 2014"," Killed"
" myServerB"," Oracle Database"," myDataBase"," default"," default"," No Job within SLA Period"," 0"," N/A"," N/A"
Entire script
# things to add
# what date was server entered in list
# how many days has server been on list
# add temp.status = pre-existing, new, removed from list
# copy sla_master before making changes. Copy to archive folder, automate rolling 90 days?
## 20150114 Created script ##
#declare global variables
$global:arrNewServers = @()
$global:arrMasterServers = @()
$global:countNewServers = 1
function Get-NewServers
Param($path)
Write-Host "Since we're skipping the 1st 6 lines, create test to check for opening lines of report from CommVault."
write-host "If not original report, break out of script"
Write-Host ""
#skip 5 to include headers, 6 for no headers
(Get-Content -path $path | Select-Object -Skip 6) | Set-Content $path
$sourceNewServers = get-content -path $path
$global:countNewServers = 1
foreach ($line in $sourceNewServers)
#declare array to hold object temporarily
$temp = @{}
$tempLine = $line.Split(",")
#get and assign values
$temp.Client = $tempLine[0].Substring(2, $tempLine[0].Length-3)
$temp.Agent = $tempLine[1].Substring(2, $tempLine[1].Length-3)
$temp.Backupset = $tempLine[3].Substring(2, $tempLine[3].Length-3)
$temp.Reason = $tempLine[5].Substring(2, $tempLine[5].Length-3)
#write temp object to array
$global:arrNewServers += New-Object -TypeName psobject -Property $temp
#increment counter
$global:countNewServers ++
Write-Host ""
$exportYN = Read-Host "Do you want to export new servers to new master list?"
$exportYN = $exportYN.ToUpper()
if ($exportYN -eq "Y")
$exportPath = Read-Host "Enter full path to export to"
Write-Host "Exporting to $($exportPath)"
foreach ($server in $arrNewServers)
$newtext = $Server.Client + ", " + $Server.Agent + ", " + $Server.Backupset + ", " + $Server.Reason
Add-Content -Path $exportPath -Value $newtext
function Get-MasterServers
Param($path)
$sourceMaster = get-content -path $path
$global:countMasterServers = 1
foreach ($line in $sourceMaster)
#declare array to hold object temporarily
$temp = @{}
$tempLine = $line.Split(",")
#get and assign values
$temp.Client = $tempLine[0]
$temp.Agent = $tempLine[1]
$temp.Backupset = $tempLine[2]
$temp.Reason = $tempLine[3]
#write temp object to array
$global:arrMasterServers += New-Object -TypeName psobject -Property $temp
#increment counter
$global:countMasterServers ++
function Compare-NewAgainstMaster
Write-Host "Total entries (arrMasterServers): $($countMasterServers)"
Write-Host "Total entries (arrNewServers): $($countNewServers)"
Write-Host "Comparing new against master"
#Compare-Object $arrMasterServers $arrNewServers
$arrDifferent = @(Compare-Object $arrMasterServers $arrNewServers)
Write-Host "There are $($arrDifferent.Count) differences."
foreach ($item in $arrDifferent)
$item
## BEGIN CODE ##
cls
$getMasterServersYN = Read-Host "Do you want to get master servers?"
$getMasterServersYN = $getMasterServersYN.ToUpper()
if ($getMasterServersYN -eq "Y")
$filePathMaster = Read-Host "Enter full path and file name to master server list"
$temp = Test-Path $filePathMaster
if ($temp -eq $false)
Read-Host "File not found ($($filePathMaster)), press any key to exit script"
exit
Get-MasterServers -path $filePathMaster
$getNewServersYN = Read-Host "Do you want to get new servers?"
$getNewServersYN = $getNewServersYN.ToUpper()
if ($getNewServersYN -eq "Y")
$filePathNewServers = Read-Host "Enter full path and file name to new server list"
$temp = Test-Path $filePathNewServers
if ($temp -eq $false)
Read-Host "File not found ($($filePath)), press any key to exit script"
exit
Get-NewServers -path $filePathNewServers
#$global:arrNewServers | format-table client, agent, backupset, reason -AutoSize
#Write-Host ""
#Write-Host "Total entries (arrNewServers): $($countNewServers)"
#Write-Host ""
#$global:arrMasterServers | format-table client, agent, backupset, reason -AutoSize
#Write-Host ""
#Write-Host "Total entries (arrMasterServers): $($countMasterServers)"
#Write-Host ""
Compare-NewAgainstMaster

do not do this:
$arrDifferent = @(Compare-Object $arrMasterServers $arrNewServers)
Try this:
$arrDifferent = Compare-Object $arrMasterServers $arrNewServers -PassThru
¯\_(ツ)_/¯
This is what made the difference. I guess you don't have to declare arrDifferent as an array, it is automatically created as an array when Compare-Object runs and fills it with the results of the compare operation. I'll look at that "pass thru" option
in a little more detail. Thank you very much!
Yes - this is the way PowerShell works.  You do not need to write so much code once you understand what PS can and is doing.
¯\_(ツ)_/¯

Similar Messages

  • I can't seem to get the Elements 10 loader to work with Windows 8.1.  Is there a workaround?

    I can't seem to get the Elements 10 loader to work with Windows 8.1.  Is there a workaround?

    Never mind.  I figured it all out.  Thanks anyway.

  • Can't seem to get Elements 8 to accept RAW files

    I have been using Elements 8 for 1-1/2 years and just made the switch to a Canon DSLR camera.  I want to generate RAW images and process them with Elements.  I just can't seem to get Elements to show a RAW converter.  Period.  I have uploaded plug-in's and even tried getting the Canon supplied photo editing program to read RAW as well.  Zilch.  What do I need to do (step by step) to get this method of image manipulation to work.  Is Elements 8 a dead horse when it comes to working with a Canon RAW file?  I'd rather not invest in a newer Elements program just yet.  Help!

    The information provided pointed me in the right direction, but the outcome was the same. Apparently, Photoshop Elements 8 needs the 6.4 version in order to be compatible with Canon RAW files.  I went back to Adobe, but they were unable to provide me with the link for the file extension (or plug-in) to make things improve.  I also installed the DNG converter, but when I tried to move over Canon RAW images, I kept getting "does not recognize file."   Huh?

  • My installation of photoshop elements 13 was interrupted, I can't seem to get it restarted, so I restarted my computer and am still unable to start the download again.  What do I do to get the download restarted?

    My installation of photoshop elements 13 was interrupted, I can't seem to get it restarted, so I restarted my computer and am still unable to start the download again.  What do I do to get the download restarted?

    Downloadable installation files available:
    Suites and Programs:  CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4, CS4 Web Standard | CS3
    Acrobat:  XI, X | 9,8 | 9 standard
    Premiere Elements:  13 | 12 | 11, 10 | 9, 8, 7 win | 8 mac | 7 mac
    Photoshop Elements:  13 |12 | 11, 10 | 9,8,7 win | 8 mac | 7 mac
    Lightroom:  5.7.1| 5 | 4 | 3
    Captivate:  8 | 7 | 6 | 5.5, 5
    Contribute:  CS5 | CS4, CS3
    Download and installation help for Adobe links
    Download and installation help for Prodesigntools links are listed on most linked pages.  They are critical; especially steps 1, 2 and 3.  If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'.

  • Can't seem to get iPhoto properly installed on my Mac OS

    hello,
    I have just purchased iPhoto, (for some reason it was not installed on my Mac originally?) - but can not seem to get it installed properly, or perhaps it IS installed, but I cannot find it. Any help for a non-technical individual? I have a MacBook Pro - with Mac OS X.
    Thanks ~
    Jenn

    Greetings,
    Click anywhere on your desktop (your background)
    Go to the "Go" menu at the top of the computer screen
    Click on applications
    Look in this list, you should see "iPhoto"
    If you can't find iPhoto in the Applications folder (where its supposed to be) try searching the computer for it:
    Click anywhere on your desktop (your background)
    Go to File > Find
    Click on "This Mac" at the top
    Type in "iPhoto.app" in the search bar on the top right
    If iPhoto shows up, drag it from the window to your desktop and then open the Applications folder (as above) and drag iPhoto to applications and try to open it up.
    If you cannot locate iPhoto, then try to download it again from the Mac App Store (Apple > App Store).  Please report any error messages you encounter verbatim.
    Hope that helps.

  • I can't seem to get the iTS to update the description of my podcast, nor refresh to show new episodes?

    I recently launched a podcast series (http://itunes.apple.com/ca/podcast/notes-from-northwest-passage/id449063851) but its still showing an older description text with some typos and an incorrect link in it, as I registered it with a pre-edited file so it would be in line for review while I finalized the details, and now I can't seem to get it to refresh and show the new texts at all, even though I edited the description texts in the xml file well over 2-3 weeks ago.
    I've tried redoing this file several times.  It always validates but changes never get picked up by the iTunes store.I can manually subscribe to the feed using iTunes' advanced menu, with no problems. The feed is at:
    http://a4.g.akamai.net/7/4/66750/v1/smb2.download.akamai.com/66750/http/podcasts /archaeology2011/arcticarchaeology2011_eng.xml
    I recently (about 3-4 days ago) tried redirecting the feed to a new version of the xml file stored in a new folder, just to see if that would somehow jolt it back into reading it, but again after 3-4 days it hasn't done anything.
    It's also not showing any of the most recent episodes even though they have all been there about a week, so the store should have picked them up by now, no?
    Any suggestions?

    If you look at the feed, and look at the entry 'The end to an exciting field season in Aulavik National Park' you will see the line:
    <pubDateFri, 29 Jul 2011 04:00:00 GMT</pubDate>
    You have not closed the 'pubdate' tag - there should be a '>' as the 9th character. Because the tag has been left open, it invalidates everything which follows it, and thus the entire feed. iTunes therefore cannot read it, which is why the Store has not updated. Add the '>' and republish, and all should be well.
    It's always worth checking your feed by subscribing manually, from the 'Advanced' menu, or by clicking the 'subscribe free' button on the Store page (both do the same thing) - if you can subscribe to the feed it should be OK.

  • I am using an iPad and iPhone and have exchange as my email. Both will only collect mails when I am in the wifi of the office, and not when I am out and about. I can't seem to get a fix for it.

    I am using an iPad and iPhone and have exchange as my email. Both will only collect mails when I am in the wifi of the office, and not when I am out and about. I can't seem to get a fix for it.

    This - https://support.mozilla.org/en-US/kb/how-make-web-links-open-firefox-default - didn't work?

  • I can't seem to get my iMac (late 2009 model) into automatic sleep mode.  If I manually put it into sleep I don't have any issues.  I used to solve the issue by running "PleaseSleep" application but that doesn't work anymore since Lion.

    I can't seem to get my iMac (late 2009 model) into automatic sleep mode.  If I manually put it into sleep I don't have any issues.
    I used to solve the issue by running "PleaseSleep" application but that doesn't work anymore since Lion. I now want to fix the underlying problem.
    I'm not running any weird background processes and in my energy saver settings I've tagged "put the hard disk to sleep when possible:, "allow power button to put computer to sleep" and "automatically reduce brigthness". All pretty standard.
    Is there anyone who can give me some pointers ?

    Today I solved the same problem for my iMac running Snow Leopard. See https://discussions.apple.com/thread/3008791#15947706. The method may help you, too.
    For me it was the DynDNS Updater preventing my iMac from automatically entering sleep mode.
    To my knowledge the cause of this sleep problem can only be a peripheral device or a process. So I suggest to first unplug all peripherals and test whether that's the cause. If not, I suggest to terminate one process after another and to test automatic entering of sleep mode after each. Start with user processes; continue with system process if necessary.
    At least that's the way I found the offending process. Fortunately, I was able to change the configuration of that process to allow again automatic entering of sleep mode.
    Good luck!

  • HT3500 I have a MacBook Pro and an HP ENVY 110 SERIES All-In-One .  I can't seem to get a network set up or either one to locate or connect to the other one.

    I've spent hours, actually probably days, trying to do this but it's not working. I've had the ENVY since Nov
    and have not been able to print - much less do anything else with it.
    My internet is CLEAR wireless. I use the little USB 4G Mobil Modem. This new HP ENVY is also wireless.
    I know I can't be online and print at the same time unless I get a router.
    I also know that I can go offline and change the network pref  to "airport" so I can print. Meaning I'll have to change
    back and forth but for my uses,  that's ok..at least for right now.
    What I can't seem to get set-up correctly is my own local network.
    I'm pretty sure it's suppose to be done using "Airport".
    Obviously, I'm doing something wrong in establishing my network.
    The printer is listed on my printer preferences and shown as  "offline"  "default". I assume that means the ENVY
    is my default printer.  Great! At least my Pro knows it's suppose to connect to the ENVY once everything's set-up correctly.
    Now, if someone could just tell me exactly, step-by-step what to do to get that done....
    I'd be soooo very happy!
    Thank you!
    Ricki

    Well... no help was found here.. so I abandoned the wireless- ness of my printer.  I bought a
    small 10 port hub because only 2 USB ports really isn't enough with wireless mouse, wireless internet
    and any kind of printer.   I also bought a long USB cable.  I now print--wired since this can be done
    as an alternative to wireless with this printer.   Because I don't want a cable "hanging around"
    when the printer is not in use, I simple disconnect it and reconnect when I want to print.
    It's a temporary solution others may find helpful as well. Apparently there's been a lot of
    confusion and problems getting this printer set up wirelessly with our MacBooks.
    Shame on HP for not helping us out!

  • I have an ipod touch and it is locked and i can't seem to get into it. what can i do to unlock it?

    i have an ipod touch and it is locked and i can't seem to get into it. what can i do to unlock it?

    You have to input your Apple ID in the prompt when it pops up

  • I have powerpoint for Mac on my imac.  I can't seem to get the active text box function to work like it did on my PC.  How can I insert an active textbox into a presentation that will allow me to type while presenting?

    I have powerpoint for Mac on my imac.  I can't seem to get the active text box function to work like it did on my PC.  How can I insert an active textbox into a presentation that will allow me to type while presenting?

    I've gotten a little further on this. The dynamic select is
    working fine. It's the "a href" code that isn't. I'm wondering if
    someone can look at this line and tell me if it's okay to build the
    query string this way. The storeid comes through fine but I'm still
    not getting the employeeid value to pass. Here's line that's not
    working:
    td><a href="registerStoreCust.php?storeid=<?php echo
    $row_storeRS['storeid']; echo "&employeeid="; echo
    $_GET['employeeLM']; ?>">Register
    Customer</a></td>

  • I can't seem to get GB to recognize my Behringer X1222 USB Mixer. It will record, but shouldn't I be able to see and/or select which input channel(s) that I will record from? Can I record more than one channel at a time, and record multi tracks?

    I can't seem to get GarageBand to recognize my Behringer X1222 USB Mixer. It will record, but only on the generic "USB Input, without seeing or letting me select the input channel from the mixer. Can't find any drivers from Behringer. How do I getGB to "see" the mixer? Thanks, I'm a newbie to Macs in genreal, and recording...

    viiram wrote:
    It will record, but only on the generic "USB Input, without seeing or letting me select the input channel from the mixer.
    the x1222 includes a 2 channel audio interface, 2 channels are all you can get from it.
    the most you can do is record to 2 tracks at a time; skim this tute to see how:
    http://www.bulletsandbones.com/GB/Tutorials.html#allaboutrecording2tracks
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • On my ipod touch, i can't seem to get the imessage app.. I have updated my itunes and even restored the ipod to factory settings with the latest update. Maybe the ipod is too old? Help

    On my ipod touch, i can't seem to get the imessage app.. I have updated my itunes and even restored the ipod to factory settings with the latest update. Maybe the ipod is too old? Is that even a thing? Is there another app I can download to have access to my contacts with imessage?

    That comes with iOS 5 (Settings>General>About>Version) and only the 3G abd later iPods can go to iOS 5 or later
    Identifying iPod models

  • HT201365 Just dowloaded the new ios 7, and i can't seem to get any apps to download in the app store. It doesn't have the meter bar anymore and all it does is have a Blue circle spin and spin for over 5 or 10 min. without nothing happening! Help !!!

    Just downloaded the new ios 7, and I can't seem to get any apps to download in the app store. It doesn't have the meter bar anymore and all it does is have a blue circle spin and spin for over 5 min. without nothing happening! Help!!!

    Hi,
    This is how App Store app shows now when an app is downloading. If you cannot download anything, go to Settings > iTunes & App Store, remove your Apple ID, and set it again. That should work.
    Hope that helps.

  • HT4623 I can't seem to get my keypad shortcuts to work on my iphone 4 after the ios6 update.  Anyone have a fix for this??  Apple???

    I can't seem to get my keypad shortcuts to work on my iphone 4 after the IOS 6 update.  Anyone have a resolution for this???  Apple???

    Unless Verizon has a special provision in this regard that ATT has never had, Apple handles all iPhone repairs and exchanges under Apple's warranty.
    There is a setting when capturing photos - Automatic, On, or Off for the flash when capturing photos.
    If there is no flash when set to On or Automatic in a dark setting and no change after the standard troubleshooting steps which in order are:
    Power your iPhone off and on.
    An iPhone reset.
    Restoring your iPhone with iTunes from the backup.
    Restoring your iPhone with iTunes as a new iPhone or not from the backup.
    Your iPhone has a hardware problem. You can call AppleCare or make an appointment at an Apple store if there is one nearby.

Maybe you are looking for