Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. clear-host
  2. $errorCode = 0
  3. $object = "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName"
  4. $logfile = "C:tempcepgogo.csv"
  5. $oldFile = "C:tempcepBook1.csv"
  6. $newFile = "C:tempcepBook2.csv"
  7. if ((Test-Path $oldFile) -And (Test-Path $newFile)) {
  8. $impFileOld = Import-Csv $oldFile -Header $object | Sort-object -Property $object -unique
  9. $impFileNew = Import-Csv $newFile -Header $object | Sort-object -Property $object -unique
  10. $result = Compare-Object $impFileOld $impFileNew -Property $object -PassThru
  11. $result | %{if ($_.SideIndicator -eq '=>') {write-host "book2"} #show result
  12. elseif($_.SideIndicator -eq '<=') {write-host "book1"}
  13. else {Add-Content $logfile "no changes found."
  14. #$errorCode = 0
  15. }
  16. }
  17. } else {
  18. Add-Content $logfile "files does not exist!"
  19. #$errorCode = 1
  20. exit 1
  21. };
  22.  
  23. clear-host
  24. $errorCode = 0
  25. $object = "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName"
  26. $logfile = "C:tempcepgogo.csv"
  27. $oldFile = "C:tempcepBook1.csv"
  28. $newFile = "C:tempcepBook2.csv"
  29. if ((Test-Path $oldFile) -And (Test-Path $newFile)) {
  30. $impFileOld = Import-Csv $oldFile -Header $object | Sort-object -Property $object -unique
  31. $impFileNew = Import-Csv $newFile -Header $object | Sort-object -Property $object -unique
  32. $result = Compare-Object $impFileOld $impFileNew -Property $object -PassThru
  33. $result | %{if ($_.SideIndicator -eq '=>') {Select-Object $object | export-csv $logfile -NoTypeInfo} #cannot print result to .csv file ????
  34. elseif($_.SideIndicator -eq '<=') {Select-Object $object | export-csv $logfile -NoTypeInfo}
  35. else {Add-Content $logfile "no changes found."
  36. #$errorCode = 0
  37. }
  38. }
  39. } else {
  40. Add-Content $logfile "files does not exist!"
  41. #$errorCode = 1
  42. exit 1
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement