Remove part of a string from a ForEach loop.

Here’s my code:

$computers = Read-host "Input comma separated computer names" $computers = $computers.Split(',').Trim() while (!$check) { foreach ($computer in $computers) { $status = manage-bde -status -computername $computer | select-string -pattern "Percent" $status = $status.Line.split(":")[1] Write-Host "$computer $status" If ($status -like "*100*") { [console]::beep(500,300) [console]::beep(500,300) $check = $true } } Write-Host "`n" start-sleep -s 60 } 

This is my “check Bitlocker status while encrypting” script. I feed it a list of computer names and it gives me a percent encrypted print out until it hits 100%.

What I’m trying to do, however, is remove computers from the loop that are 100% encrypted.

$computers = $computers.replace("$computername,","") 

However, this does not remove it from the ForEach $computers variable and instead causes the script to finish when placed above the console beep lines.

Could someone possibly point me in the right direct? Suggestions on making it more efficient are welcome as well, I haven’t messed to much with the Get-Bitlocker* commands which is why Manage-BDE is being used.

submitted by /u/bsnotreallyworking
[link] [comments]

Leave a Reply