Get-SCScript

Gets script objects from the VMM library, which allows you to view or edit any script, or to view, edit, or run a Windows PowerShell script (if you have appropriate permissions).

Description

The Get-SCScript cmdlet gets script objects from the System Center Virtual Machine Manager (VMM) library. The script file that a script object represents is stored in the file system on a library server. Typically, these scripts are either Windows PowerShell scripts or answer file scripts (including Sysprep.inf and Unattend.xml files, which contain the inputs required for the Windows Setup program).

As illustrated in the examples, you can use Get-SCScript not only to retrieve script objects but also (if you have appropriate permissions) to view the contents of a script or to edit a script. In addition, you can run the script if the following are true: 1) the script is a Windows PowerShell script, 2) scripting is enabled on your server, and 3) you have appropriate permissions (see example 5).

For information about enabling Windows PowerShell scripting on your server, type: "Get-Help about_Signing", "Get-Help Get-ExecutionPolicy -detailed", and "Get-Help Set-ExecutionPolicy -detailed".

For more information about Get-SCScript, type: "Get-Help Get-SCScript -online".

Parameters

All

Required? false
Accept Pipeline Input? false
Position? named
Retrieves a full list of all subordinate objects independent of the parent object. For example, the command Get-SCVirtualDiskDrive -All retrieves all virtual disk drive objects regardless of the virtual machine object or template object that each virtual disk drive object is associated with.

VMMServer

Required? false
Accept Pipeline Input? true (ByValue)
Position? named
Specifies a VMM server object.

FamilyName

Required? true
Accept Pipeline Input? false
Position? named
Specifies a family name for a physical resource in the VMM library. This value is used in conjunction with Release, Namespace, and Type to establish equivalency among library resources.

Release

Required? false
Accept Pipeline Input? false
Position? named
Specifies a string that describes the release of a library resource. VMM automatically creates a release value for every resource imported into the library. After the resource has been imported, the string can be customized.

VMMServer

Required? false
Accept Pipeline Input? true (ByValue)
Position? named
Specifies a VMM server object.

ID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the numerical identifier (as a globally unique identifier, or GUID) for a specific object.

VMMServer

Required? false
Accept Pipeline Input? true (ByValue)
Position? named
Specifies a VMM server object.

Name

Required? true
Accept Pipeline Input? false
Position? named
Specifies the name of a VMM object.

VMMServer

Required? false
Accept Pipeline Input? true (ByValue)
Position? named
Specifies a VMM server object.

Examples

1: Get all scripts stored on all VMM library servers.
PS C:\> Get-SCScript -VMMServer "VMMServer01.Contoso.com"
This command gets all script objects stored in library shares in the VMM library on VMMServer01, and then displays information about these scripts to the user.
2: Display specified information about all scripts on a library server.
PS C:\> Get-SCScript -VMMServer "VMMServer01.Contoso.com" | where { $_.LibraryServer.Name -eq "LibraryServer01.Contoso.com" } | Format-List -Property Name, LibraryServer, SharePath
This command gets all script objects stored on LibraryServer01 and displays the name, library server, and share path for these scripts to the user. 
3: Get all scripts with a specific name on any VMM library server.
PS C:\> Get-SCScript -VMMServer "VMMServer1.Contoso.com" | where { $_.Name -eq "Sysprep.inf" }
This command gets the answer file script objects named Sysprep.inf that are stored on any library server on VMMServer01. 

NOTE: By default, the name of a script object in the VMM library is the same name (including the file extension) as the name of the actual script file on the library server.
4: View a script that is stored in the VMM library.
PS C:\> $Script = Get-SCScript | where { $_.Name -eq "SummarizeVMMInfo.ps1"}
PS C:\> Notepad.exe $Script.SharePath
The first command gets the script object named "SummarizeVMMInfo.ps1" from the VMM library and stores the object in the $Script variable.

The second command uses Notepad to open the script so that you can view its contents (if you have the appropriate permissions to read the script). 

NOTE: If you have appropriate write permissions, you can also edit the script and save the new version.
5: Run a Windows PowerShell script that is stored in the VMM library.
PS C:\> $Script = Get-SCScript | where { $_.Name -eq "SummarizeVMMInfo.ps1" }
PS C:\> &$Script.SharePath
The first command gets the script object named "SummarizeVMMInfo.ps1" from the VMM library and stores the object in the$Script variable.

The second command uses the "&" operator to run the script stored in $Script. 

To run a Windows PowerShell script stored in a VMM library share, you must ensure the following:

- You have read and execute permissons on the script file.

- You are member of the VMM Administrators user role.

- You have permissions to access the VMM library share.

- Windows PowerShell scripting is enabled. If it isn't:

   1. Run the VMM command shell as an Administratorr.

   2. Use the Set-ExecutionPolicy cmdlet to set the execution 
	 policy to the appropriate level for your environment. 

	 For more information, type:

	 Get-Help about_Signing
	 Get-Help Get-ExecutionPolicy -detailed
	 Get-Help Set-ExecutionPolicy -detailed

See Also