There are more AWS SDK examples available in the AWS Doc SDK Examples
Use TerminateWorkspaces with a CLI
The following code examples show how to use TerminateWorkspaces.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- CLI
-
- AWS CLI
-
To terminate a WorkSpace
The following
terminate-workspacesexample terminates the specified workspace.aws workspaces terminate-workspaces \ --terminate-workspace-requestsws-dk1xzr417Output:
{ "FailedRequests": [] }For more information, see Delete a WorkSpace in the Amazon WorkSpaces Administration Guide.
-
For API details, see TerminateWorkspaces
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: Terminates multiple WorkSpaces. use of the -Force switch stops the cmdlet from prompting for confirmation.
Remove-WKSWorkspace -WorkspaceId "ws-1a2b3c4d5","ws-6a7b8c9d0" -ForceExample 2: Retrieves the collection of all your WorkSpaces and pipes the IDs to the -WorkSpaceId parameter of Remove-WKSWorkspace, terminating all of the WorkSpaces. The cmdlet will prompt before each WorkSpace is terminated. To suppress the confirmation prompt add the -Force switch.
Get-WKSWorkspaces | Remove-WKSWorkspaceExample 3: This example shows how to pass TerminateRequest objects defining the WorkSpaces to be terminated. The cmdlet will prompt for confirmation before proceeding, unless the -Force switch parameter is also specified.
$arrRequest = @() $request1 = New-Object Amazon.WorkSpaces.Model.TerminateRequest $request1.WorkspaceId = 'ws-12345678' $arrRequest += $request1 $request2 = New-Object Amazon.WorkSpaces.Model.TerminateRequest $request2.WorkspaceId = 'ws-abcdefgh' $arrRequest += $request2 Remove-WKSWorkspace -Request $arrRequest-
For API details, see TerminateWorkspaces in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: Terminates multiple WorkSpaces. use of the -Force switch stops the cmdlet from prompting for confirmation.
Remove-WKSWorkspace -WorkspaceId "ws-1a2b3c4d5","ws-6a7b8c9d0" -ForceExample 2: Retrieves the collection of all your WorkSpaces and pipes the IDs to the -WorkSpaceId parameter of Remove-WKSWorkspace, terminating all of the WorkSpaces. The cmdlet will prompt before each WorkSpace is terminated. To suppress the confirmation prompt add the -Force switch.
Get-WKSWorkspaces | Remove-WKSWorkspaceExample 3: This example shows how to pass TerminateRequest objects defining the WorkSpaces to be terminated. The cmdlet will prompt for confirmation before proceeding, unless the -Force switch parameter is also specified.
$arrRequest = @() $request1 = New-Object Amazon.WorkSpaces.Model.TerminateRequest $request1.WorkspaceId = 'ws-12345678' $arrRequest += $request1 $request2 = New-Object Amazon.WorkSpaces.Model.TerminateRequest $request2.WorkspaceId = 'ws-abcdefgh' $arrRequest += $request2 Remove-WKSWorkspace -Request $arrRequest-
For API details, see TerminateWorkspaces in AWS Tools for PowerShell Cmdlet Reference (V5).
-