![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Prompt - [WP] The following script keeps prompting for confirmation. Anyone know how to remove the confirmation when the script runs? The script reconnects a mailbox in bulk: $group = Get-Group 'exchange' $groupmembers = $group.get_members() $mailusers = Get-CASMailbox | Get-User Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | Connect-Mailbox -Database "DB1" -Confirm:$False} Advise Please. Thank you |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Prompt - [WP] I don't think that colon should be there after -confirm. Quote: > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { > Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | Connect-Mailbox > -Database "DB1" -Confirm $False} "WildPacket" wrote: Quote: > The following script keeps prompting for confirmation. Anyone know how to > remove the confirmation when the script runs? > > The script reconnects a mailbox in bulk: > > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { > Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | Connect-Mailbox > -Database "DB1" -Confirm:$False} > > Advise Please. > > Thank you > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Prompt - [WP] Set PowerShell's $ConfirmPreference to None... $ConfirmPreference = 'None' -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Prompt - [WP] Hello WILDPACKET, Quote: > The following script keeps prompting for confirmation. Anyone know > how to remove the confirmation when the script runs? > > The script reconnects a mailbox in bulk: > > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { > Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | > Connect-Mailbox > -Database "DB1" -Confirm:$False} > Advise Please. > > Thank you $oldpreference = $ConfirmPreference $ConfirmPreference = "none" $group = Get-Group 'exchange' $groupmembers = $group.get_members() $mailusers = Get-CASMailbox | Get-User Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} |Connect-Mailbox -Database "DB1"} $ConfirmPreference = $oldpreference |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Prompt - [WP] thanks all for your input. Nothing worky ..... when I remove the colon it spits error ...and when I try the other options ... the propmt still shows up. advise further please. thnQ "Karl Mitschke" wrote: Quote: > Hello WILDPACKET, > Quote: > > The following script keeps prompting for confirmation. Anyone know > > how to remove the confirmation when the script runs? > > > > The script reconnects a mailbox in bulk: > > > > $group = Get-Group 'exchange' > > $groupmembers = $group.get_members() > > $mailusers = Get-CASMailbox | Get-User > > Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { > > Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | > > Connect-Mailbox > > -Database "DB1" -Confirm:$False} > > Advise Please. > > > > Thank you > If the -confirm:$false didn't do it, try this: > > $oldpreference = $ConfirmPreference > $ConfirmPreference = "none" > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru:$True | foreach { > Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} |Connect-Mailbox > -Database "DB1"} > $ConfirmPreference = $oldpreference > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Prompt - [WP] Karl's suggestion to restore the value of $ConfirmPreference is valid when executing from the console, i.e. in the Global scope. If you change $confirmPreference's value in a script\child's scope the global $confirmPreference is not affected, execute this from the console to see: &{ sal þ write-host þ "Local `$ConfirmPreference ($ConfirmPreference) <Before>" -f 11 -b 0 $ConfirmPreference = 'None' # change local value þ "Local `$ConfirmPreference ($ConfirmPreference) <After>" -f 10 -b 0 þ "`$global:ConfirmPreference ($global:ConfirmPreference)" -f 14 -b 0 } I don't have access to Exchange Cmdlets, but given that in PowerShell some commands run in the background, maybe restoring $ConfirmPreference's value before the script exits may be causing the confirmation prompt. Try -if you haven't already - setting $ConfirmPreference to 0, or 'None', at the top of the script and _don't restore it_, then run the script. If that doesn't suppress the confirmation set $ConfirmPreference to 3, or 'High' and run the script once more. Usually setting $ConfirmPreference to 'None' or passing $false to the Cmdlet's -Confirm switch, e.g. -cf:$false or -cf:0, should suppress a Cmdlet's confirmation. v2 CTP2's Clear-History Cmdlet doesn't allow any suppression, it will always prompt for confirmation. It looks like a bug in Clear-History and _could_ also be the case for Connect-Mailbox. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Here's an excerpt from v2 CTP2's about_preference: $ConfirmPreference ------------------ Determines which cmdlet actions automatically request confirmation from the user before they are performed. When the $ConfirmPreference value (High, Medium, Low, None) is greater than or equal to the risk of the cmdlet action (High, Medium, Low, None), Windows PowerShell automatically requests confirmation from the user before performing the action. You can use the Confirm parameter of a cmdlet to override the preference for a specific command. Valid values: None: No cmdlet actions are automatically confirmed. Users must use the Confirm parameter to request confirmation of specific commands. Low: Cmdlet actions with a low, medium, or high risk are automatically confirmed. To suppress confirmation of a specific command, use -Confirm:$false. Medium: Cmdlet actions with a medium or high risk are automatically confirmed. To enable confirmation of a specific command, use -confirm. To suppress confirmation of a specific command, use -confirm:$false. High: Cmdlet actions with a high risk are automatically (default) confirmed. To enable confirmation of a specific command, use -confirm. To suppress confirmation for a specific command, use -confirm:$false. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Here's one from MSDN: "...Users can set the $ConfirmPreference shell variable so that only cmdlets and providers with an equal or higher impact level can request confirmation before they perform their operation. For example, if $ConfirmPreference is set to Medium, cmdlets and providers with a medium or high impact level can request confirmation. Requests from cmdlets and providers with a low impact level are suppressed..." http://msdn.microsoft.com/en-us/libr...ct(VS.85).aspx -- Kiron |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Prompt - [WP] Kiron thanks for your response. Can you please be more specific ...as I am not a powershell wiz ...just struggling here .... ![]() "Kiron" wrote: Quote: > Karl's suggestion to restore the value of $ConfirmPreference is valid when > executing from the console, i.e. in the Global scope. If you change > $confirmPreference's value in a script\child's scope the global > $confirmPreference is not affected, execute this from the console to see: > > &{ > sal þ write-host > þ "Local `$ConfirmPreference ($ConfirmPreference) <Before>" -f 11 -b 0 > $ConfirmPreference = 'None' # change local value > þ "Local `$ConfirmPreference ($ConfirmPreference) <After>" -f 10 -b 0 > þ "`$global:ConfirmPreference ($global:ConfirmPreference)" -f 14 -b 0 > } > > I don't have access to Exchange Cmdlets, but given that in PowerShell some > commands run in the background, maybe restoring $ConfirmPreference's value > before the script exits may be causing the confirmation prompt. > > Try -if you haven't already - setting $ConfirmPreference to 0, or 'None', > at the top of the script and _don't restore it_, then run the script. If > that doesn't suppress the confirmation set $ConfirmPreference to 3, or > 'High' and run the script once more. > > Usually setting $ConfirmPreference to 'None' or passing $false to the > Cmdlet's -Confirm switch, e.g. -cf:$false or -cf:0, should suppress a > Cmdlet's confirmation. v2 CTP2's Clear-History Cmdlet doesn't allow any > suppression, it will always prompt for confirmation. It looks like a bug > in Clear-History and _could_ also be the case for Connect-Mailbox. > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # > Here's an excerpt from v2 CTP2's about_preference: > > $ConfirmPreference > ------------------ > Determines which cmdlet actions automatically request confirmation > from the user before they are performed. > > When the $ConfirmPreference value (High, Medium, Low, None) is > greater than or equal to the risk of the cmdlet action (High, Medium, > Low, None), Windows PowerShell automatically requests confirmation > from the user before performing the action. > > > You can use the Confirm parameter of a cmdlet to override the preference > for a specific command. > > > Valid values: > None: No cmdlet actions are automatically confirmed. > Users must use the Confirm parameter to request > confirmation of specific commands. > > > Low: Cmdlet actions with a low, medium, or high risk are > automatically confirmed. To suppress confirmation > of a specific command, use -Confirm:$false. > > > Medium: Cmdlet actions with a medium or high risk are > automatically confirmed. To enable confirmation of > a specific command, use -confirm. To suppress > confirmation of a specific command, use > -confirm:$false. > > > High: Cmdlet actions with a high risk are automatically > (default) confirmed. To enable confirmation of a specific > command, use -confirm. To suppress confirmation for a > specific command, use -confirm:$false. > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # > Here's one from MSDN: > "...Users can set the $ConfirmPreference shell variable so that only > cmdlets and providers with an equal or higher impact level can request > confirmation before they perform their operation. For example, if > $ConfirmPreference is set to Medium, cmdlets and providers with a medium > or high impact level can request confirmation. Requests from cmdlets and > providers with a low impact level are suppressed..." > http://msdn.microsoft.com/en-us/libr...tomation.confi > rmimpact(VS.85).aspx > > -- > Kiron > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Prompt - [WP] I can't test this code because I don't have the Exchange Cmdlets. Copy the following code and paste it in the console, it'll create two scripts -in your current dir- named Script1.ps1 and Script2.ps1. Run Script1 first, if you still get the confirmation prompt, run Script2, if the script prompts for confirmation again, there may be a bug in Connect-Mailbox. @' #-<script1.ps1>- $confirmPreference = 'None' # confirm preference set to None $group = Get-Group 'exchange' $groupmembers = $group.get_members() $mailusers = Get-CASMailbox | Get-User Compare-Object $mailusers $groupmembers -PassThru | foreach { Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | Connect-Mailbox -Database "DB1" -Confirm:$False } '@ > Script1.ps1 @' #-<script2.ps1>- $confirmPreference = 'High' # confirm preference set to High $group = Get-Group 'exchange' $groupmembers = $group.get_members() $mailusers = Get-CASMailbox | Get-User Compare-Object $mailusers $groupmembers -PassThru | foreach { Get-MailboxStatistics | Where {$_.DisconnectDate -ne $Null} | Connect-Mailbox -Database "DB1" -Confirm:$False } '@ > Script2.ps1 # run Script1 .\Script1.ps1 # if Script1 still prompts run Script2 .\Script2.ps1 -- Kiron |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Prompt - [WP] kiron thank you man ...but the prompt seems to be coming up ... I foudn this script ....................... can this help us by any means ...if you can fix it for me? Function Should-Process ($Operation, $Target, [REF]$AllAnswer, $Warning = "", [Switch]$Verbose, [Switch]$Confirm, [Switch]$Whatif) { # Check to see if "YES to All" or "NO to all" has previously been selected # Note that this technique requires the [REF] attribute on the variable. # Here is an example of how to use this: function Stop-Calc ([Switch]$Verbose, [Switch]$Confirm, [Switch]$Whatif) { $AllAnswer = $null foreach ($p in Get-Process calc) { if (Should-Process Stop-Calc $p.Id ([REF]$AllAnswer) "`n***Are you crazy?" -Verbose:$Verbose -Confirm:$Confirm -Whatif:$Whatif) { Stop-Process $p.Id } } } if ($AllAnswer.Value -eq $false) { return $false }elseif ($AllAnswer.Value -eq $true) { return $true } if ($Whatif) { Write-Host "What if: Performing operation `"$Operation`" on Target `"$Target`"" return $false } if ($Confirm) { $ConfirmText = @" Confirm Are you sure you want to perform this action? Performing operation "$Operation" on Target "$Target". $Warning "@ Write-Host $ConfirmText while ($True) { $answer = Read-Host @" [Y] Yes [A] Yes to All [N] No [L] No to all [S] Suspend [?] Help (default is "Y") "@ switch ($Answer) { "Y" { return $true} "" { return $true} "A" { $AllAnswer.Value = $true; return $true } "N" { return $false } "L" { $AllAnswer.Value = $false; return $false } "S" { $host.EnterNestedPrompt(); Write-Host $ConfirmText } "?" { Write-Host @" Y - Continue with only the next step of the operation. A - Continue with all the steps of the operation. N - Skip this operation and proceed with the next operation. L - Skip this operation and all subsequent operations. S - Pause the current pipeline and return to the command prompt. Type "exit" to resume the pipeline. "@ } } } } if ($verbose) { Write-Verbose "Performing `"$Operation`" on Target `"$Target`"." } return $true } Thank you. "Kiron" wrote: Quote: > I can't test this code because I don't have the Exchange Cmdlets. > Copy the following code and paste it in the console, it'll create two > scripts -in your current dir- named Script1.ps1 and Script2.ps1. Run > Script1 first, if you still get the confirmation prompt, run Script2, if > the script prompts for confirmation again, there may be a bug in > Connect-Mailbox. > > @' > #-<script1.ps1>- > $confirmPreference = 'None' # confirm preference set to None > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru | foreach { > Get-MailboxStatistics | > Where {$_.DisconnectDate -ne $Null} | > Connect-Mailbox -Database "DB1" -Confirm:$False > } > '@ > Script1.ps1 > > @' > #-<script2.ps1>- > $confirmPreference = 'High' # confirm preference set to High > $group = Get-Group 'exchange' > $groupmembers = $group.get_members() > $mailusers = Get-CASMailbox | Get-User > Compare-Object $mailusers $groupmembers -PassThru | foreach { > Get-MailboxStatistics | > Where {$_.DisconnectDate -ne $Null} | > Connect-Mailbox -Database "DB1" -Confirm:$False > } > '@ > Script2.ps1 > > > # run Script1 > .\Script1.ps1 > > # if Script1 still prompts run Script2 > .\Script2.ps1 > > > -- > Kiron > |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Prompt - [WP] I don't see how the Should-Process function could help since the Connect-Mailbox Cmdlet's ConfirmImpact and the session's $confirmPreference value determine if and when to prompt for confirmation. A developer in this NG can explain the wiring of ShouldProcess, ConfirmImpact, YesToAll and NoToAll in a Cmdlet, I'm not a developer, sorry. Someone in this NG with access to Exchange Cmdlets can test your mailbox reconnecting script with the suggestions made and verify whether the Cmdlet has a bug or not. Sorry my suggestions didn't help WildPacket. -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Uac prompt | General Discussion | |||
| Re: Where is the dos prompt? | Vista General | |||
| Log in prompt | Live Mail | |||
| DOS Prompt Here | Vista General | |||
| Run As doesn't prompt | Vista General | |||