Remove-SCScript

Remove-SCScript

Removes a script object from VMM.

Syntax

Parameter Set: Default
Remove-SCScript [-Script] <Script> [-Force] [-JobVariable <String> ] [-PROTipID <Guid]> ] [-RunAsynchronously] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The Remove-SCScript cmdlet removes one or more script objects from the Virtual Machine Manager (VMM) library and deletes the corresponding script file on the library server.

If the script is attached to a template or hardware profile, and if you do not use the Force parameter, VMM lists the container that contains the script and prompts you to confirm that you want to remove the script:

-- If you reply Yes, VMM removes the association between the script and the container to which it is attached, and then deletes the script object from VMM.

-- If you reply No, the operation is cancelled.

This cmdlet returns the object upon success, with the property MarkedForDeletion set to TRUE, or returns an error message upon failure.

Parameters

-Force

Forces the operation to complete.

For example:

- Remove-SCSCVMHost -Force

Forces the removal of a host object from the VMM database.

- Stop-SCVirtualMachine -Force

Stops a virtual machine.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-JobVariable<String>

Specifies that job progress is tracked and stored in the variable named by this parameter.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PROTipID<Guid]>

Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RunAsynchronously

Indicates that the job runs asynchronously so that control returns to the command shell immediately.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Script<Script>

Specifies a VMM script object.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

Examples

Example 1: Remove a script object and delete the corresponding script file

The first command gets the script object named AddHost.ps1 from the VMM library on VMMServer01, and then stores the object in the array named $Scripts. More than one file with the same name might exist if more than one container for scripts exists on the specified library server.

The second command counts the number of scripts in $Scripts and displays the results.

The third command passes each script object in $Scripts to the Select-Object cmdlet, which selects the name and share path for each script in the array. The command then passes these results to the Format-List cmdlet to display each script name, and its share path. For more information, type Get-Help Select-Object and Get-Help Format-List.

The last command deletes the first object in the $Scripts array. The command specifies the Force parameter to ensure that the script object is removed from the VMM database and that the corresponding script file is deleted from the file system on the library server.

PS C:\> $Scripts = @(Get-SCScript -VMMServer "VMMServer01.Contoso.com" | where { $_.LibraryServer.Name -eq "LibraryServer01.Contoso.com" -and $_.Name -eq "AddHost.ps1"} )
PS C:\> $Scripts.Count
PS C:\> $Scripts | select Name,SharePath | Format-List
PS C:\> Remove-SCScript -Script $Scripts[0] -Force

Example 2: Remove multiple scripts from the library

The first command gets all script objects whose names include the string Sysprep from VMMServer01, and then stores these objects in the array named $Scripts.

The second command passes each script object in $Scripts to Remove-SCScript, which removes each script object from the library and deletes each corresponding script file from the file system on the library server.

The second command specifies the Confirm parameter. The command prompts you to confirm that you do want to remove these scripts. You have the option to confirm the deletion of all scripts at once or to confirm the deletion of each script one-by-one.

PS C:\> $Scripts = Get-SCScript -VMMServer "VMMServer01.Contoso.com" | where { $_.Name -match "Sysprep" }
PS C:\> $Scripts | Remove-SCScript -Confirm

Get-SCScript

Set-SCScript