Remove-SCScript
Applies To: System Center 2012 - Virtual Machine Manager
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 System Center 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.
For more information about Remove-SCScript, type: "Get-Help Remove-SCScript -online".
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? |
true (ByValue) |
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 executing the command.
Required? |
false |
Position? |
named |
Default Value |
false |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-WhatIf
Describes what would happen if you executed the command without actually executing the command.
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.
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
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 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 $Scrips and displays the results to the user.
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, to the user.
The last command deletes the first object in the $Scripts array and uses the Force parameter to ensure that the script object is removed from the VMM database and 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
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-Script, which removes each script object from the library and deletes each corresponding script file from the file system on the library server.
The Confirm parameter 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