Script – Join a Computer to the Domain

Join the local computer to the domain without prompting  using a specific account and reboot once finished.

Add-Computer -DomainName testdom.local -NewName Server22 -Credential testdom\administrator -Restart -Force
Advertisements

Script – New AD Forest

This PowerShell script will deploy a new root forest with a forest and domain level of Windows Server 2012 R2.

Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012R2" `
-DomainName "test.local" `
-DomainNetbiosName "TEST" `
-ForestMode "Win2012R2" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

 

PowerShell – Dynamically Adding the Cireson Asset Management Organisation to a Work Item

I wrote a post a little while back that demonstrates how to automatically add the relevant customer to an Incident.  It assumes I created a new class called Customer Organisation.

However, if you are using the Cireson Asset Management app then you could use the Organisation class that comes with this app.

This assumes you author a relationship between the Organisation class and the Incident Class.

I use the same command to store the relationship as a variable.

#Store the relationship types as a variables
$CORel = Get-SCSMRelationship -Name "RelatedCustomerOrganisation"

Here is the key difference in the script – specifying the Cireson AM Organisation.

# Obtain the Customer Organisation where the name matches the users Company property
$CO = Get-SCSMClassInstance -Class (Get-SCSMClass -Name Cireson.AssetManagement.Organization) | ? {$_.DisplayName -eq $AU.Company}

The full script is here.

Import-Module 'C:\Program Files\Microsoft System Center 2012 R2\Service Manager\Powershell\System.Center.Service.Manager.psd1'

#Store the relationship types as a variables
$CORel = Get-SCSMRelationship -Name "RelatedCustomerOrganisation"
$AURel = Get-SCSMRelationship -Name "System.WorkItemAffectedUser"

# Get the Incident
$IR = Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Incident) | ? {$_.ID -eq "$GUID"}

# Use the method to return the related Affected User object GUID and save it to a variable
$AffectedUserGUID = $IR.GetRelatedObjectsWhereSource($AURel.ID).EnterpriseManagementObject.id.GUID

# If related Affected User is returned then process the remainder of the script
if ($AffectedUserGUID -ne $null)

{

    # Obtain CI info about the Affected User
    $AU = Get-SCSMClassInstance -ID $AffectedUserGUID

    # Obtain the Customer Organisation where the name matches the users Company property
    $CO = Get-SCSMClassInstance -Class (Get-SCSMClass -Name Cireson.AssetManagement.Organization) | ? {$_.DisplayName -eq $AU.Company}

    # If a match between the user and the Customer Organisation is found then create the relationship
    if ($CO -ne $null)

        {

            #Create the relationship between the Incident and the Customer Organisation CI
            New-SCRelationshipInstance -RelationshipClass $COREL -Source $CO -Target $IR

        }

}