Skip to content

Instantly share code, notes, and snippets.

@Cyreex
Created April 10, 2017 14:47
Show Gist options
  • Save Cyreex/5cf7b3a2b3c10b4c9737b711f1ec52bc to your computer and use it in GitHub Desktop.
Save Cyreex/5cf7b3a2b3c10b4c9737b711f1ec52bc to your computer and use it in GitHub Desktop.
Integration-Services-Customization
workflow Integration-Services-Customization
{
param
(
[Parameter(Mandatory=$true)]
[String] $VMMJOBID
)
#Constants
$TargetProp = "CustomProp"
$Evaluate = "Evaluatea"
$PDC = "PDC"
# Connection to access VMM server
$VmmConnection = Get-AutomationConnection -Name 'VmmConnection'
$VmmServerName = $VmmConnection.ComputerName
$SecurePassword = ConvertTo-SecureString -AsPlainText -String $VmmConnection.Password -Force
$VmmCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $VmmConnection.Username, $SecurePassword
inlinescript {
# Import VMM module.
Import-Module virtualmachinemanager
# Connect to VMM server.
Get-SCVMMServer -ComputerName $Using:VmmServerName -ForOnBehalfOf
# if vmmjobid eq 0 - it test task (no job)
$job = Get-SCJob -ID $USING:vmmjobid
# Check Job Status
$JobStatus=$Job.Status
# Wait Until Task Completed
while ($JobStatus -eq "Running") {
write-output "Start Sleep"
start-sleep 5
$JobStatus=$Job.Status
}
# Break if Job failed
if ($JobStatus -eq "Failed") {
write-output "Job Failed!"
write-output JOBid:$job.ID
break
}
# Get target VM
$VMid = ($fulljob.AuditRecords.objectdata).ID
$VM = Get-SCVirtualMachine -ID $VMid
$CustomProp = Get-SCCustomProperty -Name $USING:TargetProp
$CustomPropValue = (Get-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomProp).Value
# Integration Services Disable
if ($CustomPropValue -eq $USING:Evaluate) {
Set-SCVirtualMachine $vm -EnableDataExchange $false
}
if ($CustomPropValue -eq $USING:PDC) {
Set-SCVirtualMachine $vm -EnableTimeSynchronization $false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment