Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
Hi,
Anyone knows how to convert "echo Y |" dos command in PowerShell?
Thanks
Charles
Without knowing what your trying to do, have you tried {'y' | your command.exe}. Without detailes it's hard to telll why the pipline isn't working. If you tell us what your trying to do we can explore other options.
~Glenn
Hi Glenn,
I am new to PowerShell.. What I am trying to do is piping Echo Y | to Remove-NaSnapshot..
The goal is to delete orphaned snapshot(s) from all the iSCSI volumes that start with {
Example: {93101811-e57c-4627-939a-46580448f181}
PS C:\Windows\system32> $VOLList = Get-NaVol
PS C:\Windows\system32> $myvar=”{*”
PS C:\Windows\system32> ForEach ($_.Name in $VOList) {Get-NaSnapshot $_.Name $myvar | Remove-NaSnapshot | write-host "Y"}
Delete snapshot
Are you sure you want to delete snapshot {93101811-e57c-4627-939a-46580448f181} from volume FFXCMGC01_SQL_DB?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?]
PS C:\Windows\system32>>> ForEach ($_.Name in $VOLList) {Get-NaSnapshot $_.Name $myvar | Remove-NaSnapshot | echo Y}
Delete snapshot
Are you sure you want to delete snapshot {93101811-e57c-4627-939a-46580448f181} from volume FFXCMGC01_SQL_DB?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Delete snapshot
Are you sure you want to delete snapshot {9b98763a-3e0a-4fd4-b40a-5129b787dd88} from volume FFXCMGC01_SQL_DB?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Thanks
Charles
Hi Charles,
Great question! Most PowerShell cmdlets (not just the toolkit) that prompt the user for confirmation have a "-Confirm" switch. You can try something like this:
Get-NaVol | Get-NaSnapshot -SnapName "{*" | Remove-NaSnapshot -Confirm
Cheers,
Eric
Just to clarify, if you want to suppress the confirmation, you would use "-Confirm:$false":
Remove-NaSnapshot $volName $snapName -Confirm:$false
You can also look into the $ConfirmPreference variable, which will control the confirmation prompt for all cmdlets. The help topic about_Preference_Variables contains information about the $ConfirmPreference variable:
help about_Preference_Variables
Hope that helps!
-Steven
Ohh Eric so close
Charles,
PowerShell uses a series of common parameters to universally controll the behavior of all cmdlet. Any cmdlet that prompts for confirmation is doing so by upgrading the -confirm switch. You can inturn either, make any command prompt by adding the confirm switch as Eric did. Or you can override it by supplying a negetive confirm value.
Get-NaVol | Get-NaSnapshot -SnapName "{*"| Remove-NaSnapShot -confirm:$false
for more information on how this all works just type "help about_commonparameters" from any powershell prompt.
Hope that helps,
~Glenn
Thank You All (Glenn, Eric, and Beam)..
It is so amaze how powershell can do . It turns my 45+ lines dos command into just 3 statements
Charles