help with compare-object in powershell

wsousa1wsousa1 Member Posts: 8 ■□□□□□□□□□
i'm very new to powershell and what i'm attempting to do is automate code releases into production by using some form of verification check during the process to ensure files have been copied.

after i copy-item from source to destination, i want to be able to:

1. compare the size of folder1 and folder2
2. if the sum is different, stop script and email a transcript of the error for further revision
3. if sum of folder1 and folder2 are the same, continue

Any help with this would be much appreciated.



  • Options
    NetworkNewbNetworkNewb Member Posts: 3,298 ■■■■■■■■■□
    If you Google how to find the size of the folder with powershell, you will find examples of functions people have created to find it. I would just use one of those functions and compare the results of the function when used with folder1 and folder2 as parameters. For example if the function was name GetFolderSize it would be something like:

    if((GetFolderSize folder1) -ne (GetFolderSize folder2)) { insert code here to email transcript and stop script }

    Then if they are the same size the script would just skip that and continue on.
  • Options
    wsousa1wsousa1 Member Posts: 8 ■□□□□□□□□□
    Very helpful thank you. i was able to create the two functions. Only issue is when i run the script, even though the 2 folders are exactly the same size it still sends an email.
  • Options
    NetworkNewbNetworkNewb Member Posts: 3,298 ■■■■■■■■■□
    what you will want to do is make sure the function that you found is spitting out the correct numbers and not just the same thing every time.

    Could just call the function by itself, without the rest your script, and return the value to see what it says. Or you can also plug random numbers in your script, where you called the function, to see if it works without the function. Something like :

    if(1 -ne 3) { insert code here to email transcript and stop script }

    Im completely guessing but think you are going to have to troubleshoot the function itself or find another function online.
Sign In or Register to comment.