Christophe
asked on
Powershell do until
Hello,
I am trying to write script but I have no enough powershell experience to do that. I would like to have a loop until a condition is true.
For my project I need to check if a CD or dvd inserted is blank or not. I found I can check with "Get-Volume | select -property operationalStatus | Where-Object {$_.operationalStatus -eq "Unknown"} " When media is blank operationalstatus is alway Unknown.
I have started to write like that (see below) but it does not work. I am not surprised I do not know how to do that :-)
I would like to continue to show a warning until blank CD is inserted and then continue to action. I do not know how to build a loop until the condition is true.
Thank you in advance for your help and sorry for my bad english. I am a french who did not work during english lessons at school :-)
I am trying to write script but I have no enough powershell experience to do that. I would like to have a loop until a condition is true.
For my project I need to check if a CD or dvd inserted is blank or not. I found I can check with "Get-Volume | select -property operationalStatus | Where-Object {$_.operationalStatus -eq "Unknown"} " When media is blank operationalstatus is alway Unknown.
I have started to write like that (see below) but it does not work. I am not surprised I do not know how to do that :-)
I would like to continue to show a warning until blank CD is inserted and then continue to action. I do not know how to build a loop until the condition is true.
Thank you in advance for your help and sorry for my bad english. I am a french who did not work during english lessons at school :-)
$OS = Get-Volume | select -property operationalStatus | Where-Object {$_.operationalStatus -eq "Unknown"}
Do{
If ($OS.operationalStatus -eq "Unknown")
{
Start-Process -Wait "C:\Program Files (x86)\softwarexxx"
}
Else {
[System.Windows.Forms.MessageBox]::Show("CD/DVD inserted is not blank")
Start-Process -Wait "C:\Program Files (x86)\CDBurnerXP\cdbxpcmd.exe" -ArgumentList "--eject [ -device:1 ]"
[System.Windows.Forms.MessageBox]::Show("Please insert a blank CD/DVD and click OK")
Start-Process -Wait "C:\Program Files (x86)\CDBurnerXP\cdbxpcmd.exe" -ArgumentList "--wait-for-disc [ -device:$Devicenumber ]"
}
}
Until ($OS -eq "Unknown")
Where are you going to define $Devicenumber in line 9
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello,
I have just tried your script. I am sorry it does not work like it should works. I have inserted a blank CD and I get message "CD/DVD inserted is not blank".
First process I have inserted blank CD. I've got "CD/DVD inserted is not blank". Script continues to steps "eject, ("Please insert a blank CD/DVD and click OK"), wait-for-disc. I just inserted same blank CD and script has continued to step Write-Output("Blank CD Inserted")
Second process I've tried with non blank CD. I've got "CD/DVD inserted is not blank". Script continues to steps "eject, ("Please insert a blank CD/DVD and click OK"), wait-for-disc. I've inserted blank CD and script has continued to step Write-Output("Blank CD Inserted"). it works
It is just for the first process that there is a problem. If a blank CD is already inserted script should continue to step Write-Output("Blank CD Inserted") and not to "CD/DVD inserted is not blank" step
Thanks
I have just tried your script. I am sorry it does not work like it should works. I have inserted a blank CD and I get message "CD/DVD inserted is not blank".
First process I have inserted blank CD. I've got "CD/DVD inserted is not blank". Script continues to steps "eject, ("Please insert a blank CD/DVD and click OK"), wait-for-disc. I just inserted same blank CD and script has continued to step Write-Output("Blank CD Inserted")
Second process I've tried with non blank CD. I've got "CD/DVD inserted is not blank". Script continues to steps "eject, ("Please insert a blank CD/DVD and click OK"), wait-for-disc. I've inserted blank CD and script has continued to step Write-Output("Blank CD Inserted"). it works
It is just for the first process that there is a problem. If a blank CD is already inserted script should continue to step Write-Output("Blank CD Inserted") and not to "CD/DVD inserted is not blank" step
Thanks
Whose "your" script?
ASKER
David Johnson. I did not tried your script yet (oBdA)
Thanks for your help
Thanks for your help
ASKER
Awesome! Very good script. It works perfectly. Thank you for your help!
Open in new window