@@ -405,16 +405,17 @@ Describe "Invoke-UserHunter" {
405405 Throw " Insuffient results returned"
406406 }
407407 }
408- It " Should accept -ComputerFile argument" {
409- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
410- if ( (Invoke-UserHunter - ComputerFile " .\targets.txt" - ShowAll | Measure-Object ).count -lt 1 ) {
411- Remove-Item - Force " .\targets.txt"
412- Throw " Insuffient results returned"
413- }
414- else {
415- Remove-Item - Force " .\targets.txt"
408+ try {
409+ It " Should accept -ComputerFile argument" {
410+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
411+ if ( (Invoke-UserHunter - ComputerFile " .\targets.txt" - ShowAll | Measure-Object ).count -lt 1 ) {
412+ Throw " Insuffient results returned"
413+ }
416414 }
417415 }
416+ finally {
417+ Remove-Item - Force " .\targets.txt"
418+ }
418419 It " Should accept -NoPing flag" {
419420 if ( (Invoke-UserHunter - ComputerName " $env: computername .$env: userdnsdomain " - UserName $env: USERNAME - NoPing | Measure-Object ).count -lt 1 ) {
420421 Throw " Insuffient results returned"
@@ -447,31 +448,33 @@ Describe "Invoke-ProcessHunter" {
447448 Throw " Insuffient results returned"
448449 }
449450 }
450- It " Should accept -ComputerFile argument" {
451- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
452- if ( (Invoke-ProcessHunter - ComputerFile " .\targets.txt" - UserName $env: USERNAME | Measure-Object ).count -lt 1 ) {
453- Remove-Item - Force " .\targets.txt"
454- Throw " Insuffient results returned"
455- }
456- else {
457- Remove-Item - Force " .\targets.txt"
451+ try {
452+ It " Should accept -ComputerFile argument" {
453+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
454+ if ( (Invoke-ProcessHunter - ComputerFile " .\targets.txt" - UserName $env: USERNAME | Measure-Object ).count -lt 1 ) {
455+ Throw " Insuffient results returned"
456+ }
458457 }
459458 }
459+ finally {
460+ Remove-Item - Force " .\targets.txt"
461+ }
460462 It " Should accept -ProcessName argument" {
461463 if ( (Invoke-ProcessHunter - ComputerName " $env: computername .$env: userdnsdomain " - ProcessName powershell | Measure-Object ).count -lt 1 ) {
462464 Throw " Insuffient results returned"
463465 }
464466 }
465- It " Should accept -UserFile argument" {
466- " $env: USERNAME " | Out-File - Encoding ASCII target_users.txt
467- if ( (Invoke-ProcessHunter - ComputerName " $env: computername .$env: userdnsdomain " - UserFile " .\target_users.txt" | Measure-Object ).count -lt 1 ) {
468- Remove-Item - Force " .\target_users.txt"
469- Throw " Insuffient results returned"
470- }
471- else {
472- Remove-Item - Force " .\target_users.txt"
467+ try {
468+ It " Should accept -UserFile argument" {
469+ " $env: USERNAME " | Out-File - Encoding ASCII target_users.txt
470+ if ( (Invoke-ProcessHunter - ComputerName " $env: computername .$env: userdnsdomain " - UserFile " .\target_users.txt" | Measure-Object ).count -lt 1 ) {
471+ Throw " Insuffient results returned"
472+ }
473473 }
474474 }
475+ finally {
476+ Remove-Item - Force " .\target_users.txt"
477+ }
475478 It " Should accept -NoPing flag" {
476479 if ( (Invoke-ProcessHunter - ComputerName " $env: computername .$env: userdnsdomain " - UserName $env: USERNAME - NoPing | Measure-Object ).count -lt 1 ) {
477480 Throw " Insuffient results returned"
@@ -496,16 +499,17 @@ Describe "Invoke-ShareFinder" {
496499 Throw " Insuffient results returned"
497500 }
498501 }
499- It " Should accept -ComputerFile argument" {
500- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
501- if ( (Invoke-ShareFinder - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
502- Remove-Item - Force " .\targets.txt"
503- Throw " Insuffient results returned"
504- }
505- else {
506- Remove-Item - Force " .\targets.txt"
502+ try {
503+ It " Should accept -ComputerFile argument" {
504+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
505+ if ( (Invoke-ShareFinder - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
506+ Throw " Insuffient results returned"
507+ }
507508 }
508509 }
510+ finally {
511+ Remove-Item - Force " .\targets.txt"
512+ }
509513 It " Should accept -ExcludeStandard argument" {
510514 {Invoke-ShareFinder - ComputerName " $env: computername .$env: userdnsdomain " - ExcludeStandard} | Should Not Throw
511515 }
@@ -551,14 +555,22 @@ Describe "Invoke-FileFinder" {
551555 It " Should accept -ComputerName argument" {
552556 {Invoke-FileFinder - ComputerName " $env: computername .$env: userdnsdomain " } | Should Not Throw
553557 }
554- It " Should accept -ComputerFile argument" {
555- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
556- {Invoke-FileFinder - ComputerFile " .\targets.txt" } | Should Not Throw
558+ try {
559+ It " Should accept -ComputerFile argument" {
560+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
561+ {Invoke-FileFinder - ComputerFile " .\targets.txt" } | Should Not Throw
562+ }
563+ }
564+ finally {
557565 Remove-Item - Force " .\targets.txt"
558566 }
559- It " Should accept -ShareList argument" {
560- " \\$ ( $env: computername ) \\IPC$" | Out-File - Encoding ASCII shares.txt
561- {Invoke-FileFinder - ShareList " .\shares.txt" } | Should Not Throw
567+ try {
568+ It " Should accept -ShareList argument" {
569+ " \\$ ( $env: computername ) \\IPC$" | Out-File - Encoding ASCII shares.txt
570+ {Invoke-FileFinder - ShareList " .\shares.txt" } | Should Not Throw
571+ }
572+ }
573+ finally {
562574 Remove-Item - Force " .\shares.txt"
563575 }
564576 It " Should accept -Terms argument" {
@@ -609,16 +621,17 @@ Describe "Find-LocalAdminAccess" {
609621 Throw " Insuffient results returned"
610622 }
611623 }
612- It " Should accept -ComputerFile argument" {
613- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
614- if ( (Find-LocalAdminAccess - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
615- Remove-Item - Force " .\targets.txt"
616- Throw " Insuffient results returned"
617- }
618- else {
619- Remove-Item - Force " .\targets.txt"
624+ try {
625+ It " Should accept -ComputerFile argument" {
626+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
627+ if ( (Find-LocalAdminAccess - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
628+ Throw " Insuffient results returned"
629+ }
620630 }
621631 }
632+ finally {
633+ Remove-Item - Force " .\targets.txt"
634+ }
622635 It " Should accept -NoPing argument" {
623636 if ( (Find-LocalAdminAccess - NoPing - ComputerName " $env: computername .$env: userdnsdomain " | Measure-Object ).count -lt 1 ) {
624637 Throw " Insuffient results returned"
@@ -643,16 +656,17 @@ Describe "Invoke-EnumerateLocalAdmin" {
643656 Throw " Insuffient results returned"
644657 }
645658 }
646- It " Should accept -ComputerFile argument" {
647- " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
648- if ( (Invoke-EnumerateLocalAdmin - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
649- Remove-Item - Force " .\targets.txt"
650- Throw " Insuffient results returned"
651- }
652- else {
653- Remove-Item - Force " .\targets.txt"
659+ try {
660+ It " Should accept -ComputerFile argument" {
661+ " $env: computername .$env: userdnsdomain " , " $env: computername .$env: userdnsdomain " | Out-File - Encoding ASCII targets.txt
662+ if ( (Invoke-EnumerateLocalAdmin - ComputerFile " .\targets.txt" | Measure-Object ).count -lt 1 ) {
663+ Throw " Insuffient results returned"
664+ }
654665 }
655666 }
667+ finally {
668+ Remove-Item - Force " .\targets.txt"
669+ }
656670 It " Should accept -NoPing argument" {
657671 if ( (Invoke-EnumerateLocalAdmin - NoPing - ComputerName " $env: computername .$env: userdnsdomain " | Measure-Object ).count -lt 1 ) {
658672 Throw " Insuffient results returned"
0 commit comments