In a previous blog post I created a PowerShell script that would automatically populate the relationship property for the Customer Organisation class when an Incident is created.
A PowerShell snippet below can be plugged into the original PowerShell script that will automatically create the Customer Organisation if it doesn’t already exist.
# If no match between the user and the Customer Organisation is found then create the Customer Organisation CI and then create the relationship if ($CO -eq $null) { # Get the class for Customer Organisation $COClass = Get-SCSMClass -Name "CustomerOrganisation" # Define the properties that will populate the class instance $Properties = @{DisplayName = "$AU.Company"} # Create the class instance $COCI = New-SCSMClassInstance -Class (Get-SCSMClass -Name $COClass) -property $Properties #Create the relationship between the Incident and the new Customer Organisation CI New-SCRelationshipInstance -RelationshipClass $COREL -Source $COCI -Target $IR }
It uses an If statement, however in the original script there is already an If statement that looks for the CO null value, so if you do plug it in, it may be more efficient to use an Else statement instead.
Happy scripting!