Please help with this script

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #6292

    by danielson1 at 2013-02-26 18:34:33

    Found some code from Shay Levy that I'm trying to use to generate an OU structure for a SharePoint environment:
    Get-Content 'OrgUnits.csv' | Foreach-Object{
    $ParentContainer = Split-Path $_
    $Name = Split-Path $_ -Leaf
    New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentContainer -WhatIf
    }

    getting the following errors as I iterate through the objects:
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:4 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    OrgUnits.csv structure is as follows (The RootOU already Exists)]
    Domain RootOU Enclave Classification Environment Type
    a.com Sharepoint External Moderate Production Service
    a.com Sharepoint External Moderate Production Computer
    a.com Sharepoint External Moderate Staging Service
    a.com Sharepoint External Moderate Staging Computer
    a.com Sharepoint External Moderate Development Service
    a.com Sharepoint External Moderate Development Computer
    a.com Sharepoint External Low Production Service
    a.com Sharepoint External Low Production Computer
    a.com Sharepoint External Low Staging Service
    a.com Sharepoint External Low Staging Computer
    a.com Sharepoint External Low Development Service
    a.com Sharepoint External Low Development Computer
    a.com Sharepoint Internal Moderate Production Service
    a.com Sharepoint Internal Moderate Production Computer
    a.com Sharepoint Internal Moderate Staging Service
    a.com Sharepoint Internal Moderate Staging Computer
    a.com Sharepoint Internal Moderate Development Service
    a.com Sharepoint Internal Moderate Development Computer
    a.com Sharepoint Internal Low Production Service
    a.com Sharepoint Internal Low Production Computer
    a.com Sharepoint Internal Low Staging Service
    a.com Sharepoint Internal Low Staging Computer
    a.com Sharepoint Internal Low Development Service
    a.com Sharepoint Internal Low Development Computer

    Thanks in advance for any input!

    by compugab at 2013-02-27 03:34:41

    Hi,

    I was wondering what¸happen if you show the value of $Name and $ParentContainer. Might be where the problem is. Could you execute you script like this :

    Get-Content 'OrgUnits.csv' | Foreach-Object{
    $ParentContainer = Split-Path $_
    $Name = Split-Path $_ -Leaf
    "Name : $Name"
    "ParentContainer : $ParentContainer"
    }

    Thanks

    by MaxMad at 2013-02-27 04:55:10

    Why you don't you use import-csv and work with objects and properties?

    import-csv .\test.csv -Delimiter "`t" | Foreach-Object {
    $ParentContainer = $_.RootOU
    $Name = $_.Enclave
    ...

    by danielson1 at 2013-02-27 05:55:01

    Added -Delimeter "`t", used import-csv instead of get-object, and commented the New-QADObject cmdlet

    Import-Csv 'OrgUnits.csv' -Delimiter "`t" | Foreach-Object{
    $ParentContainer = Split-Path $_
    $Name = Split-Path $_ -Leaf

    "Name = $Name"
    "ParentContrainer : $ParentContainer"

    #New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentContainer -WhatIf
    }

    The output is as follows when I run the script as @compugab recommends]
    Name = @{Type,Environment,Classification,Enclave=Service,Production,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Production,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Staging,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Staging,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Development,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Development,Moderate,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Production,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Production,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Staging,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Staging,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Development,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Development,Low,External}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Production,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Production,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Staging,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Staging,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Development,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Development,Moderate,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Production,Low,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Production,Low,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Staging,Low,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Staging,Low,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Service,Development,Low,Internal}
    ParentContrainer :
    Name = @{Type,Environment,Classification,Enclave=Computer,Development,Low,Internal}
    ParentContrainer :
    Changed Delimiter to "," – read in csv with Get-Content again
    Get-Content 'OrgUnits.csv' -Delimiter "," | Foreach-Object{
    $ParentContainer = Split-Path $_
    $Name = Split-Path $_ -Leaf

    "Name = $Name"
    "ParentContrainer : $ParentContainer"

    New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentContainer -WhatIf
    }

    Output:
    Name = Type,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Environment,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Classification,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Enclave
    Service,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Production,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Moderate,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = External
    Computer,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    Name = Production,
    ParentContrainer :
    New-QADObject : Cannot resolve directory object for the given identity: ".
    At line:8 char:2
    + New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentCont ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-QADObject], ObjectNotFoundException
    + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.A
    ctiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewObjectCmdlet

    by MaxMad at 2013-02-27 06:11:26

    Stop working with split-path and use the properties directly. First example with the delimter "Tab" (`t) worked.
    Build your Variables with the properties of the objects after importing with import-csv. After using import-csv with the correct delimiter you can access each property by the property name you specified in the .csv header!

    Import-Csv 'OrgUnits.csv' -Delimiter "`t" | Foreach-Object{
    $ParentContainer = "ou=" + $_.RootOU + ",ou=" + $_.Environment
    "ParentContrainer : $ParentContainer"

    #New-QADObject -Name $Name -Type OrganizationalUnit -ParentContainer $ParentContainer -WhatIf
    }

    by danielson1 at 2013-02-27 06:47:25

    Thanks for the tip on using the tab delim. Forgive me for being a bit dense here, but the $parentcontainer variable needs to change with each iteration correct? For instance the parent container for the "computer" ou in a.com/sharepoint/external/low will be 'ou=low,...'

    The problem for the script is that only the 'Sharepoint' ou has thus far been created. I need to create each 'ou' (External, Internal — then Moderate and Low for each, then Production, Staging, Dev and finally Computer and Service)

You must be logged in to reply to this topic.