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.

Syntax

Get-SCScript
   [-VMMServer <ServerConnection>]
   [-All]
   [<CommonParameters>]
Get-SCScript
   [-VMMServer <ServerConnection>]
   -Name <String>
   [<CommonParameters>]
Get-SCScript
   [-VMMServer <ServerConnection>]
   [-Release <String>]
   -FamilyName <String>
   [<CommonParameters>]
Get-SCScript
   [-VMMServer <ServerConnection>]
   [-ID <Guid>]
   [<CommonParameters>]

Description

The Get-SCScript cmdlet gets script objects from the 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.

Examples

Example 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.

Example 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.

Example 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.

Example 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.

Example 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 ampersand (&) 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 permissions 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 Administrator. 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, and Get-Help Set-ExecutionPolicy -Detailed

Required Parameters

-FamilyName

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.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Name

Specifies the name of a VMM object.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-All

Indicates that this cmdlet gets all subordinate objects independent of the parent object. For example, the command Get-SCVirtualDiskDrive -All gets all virtual disk drive objects regardless of the virtual machine object or template object that each virtual disk drive object is associated with.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ID

Specifies the numerical identifier as a globally unique identifier, or GUID, for a specific object.

Type:Guid
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Release

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.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-VMMServer

Specifies a VMM server object.

Type:ServerConnection
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False

Outputs

Script

This cmdlet returns a Script object.