locked
GetCMDevice results to pass to Get-ChildItem RRS feed

  • Question

  • Hello,

    I have the script:

    Get-CMDevice -CollectionID UCP0088F | ForEach-Object {$_.Name} 
    $Name = {$_.Name}
    $DeptIDsAllowed 
    Get-ChildItem "\\$Name\C$\Program Files\CCSI\800\8001\OBIXConfig\defaults.ini" |
     Get-Content | Select-String "DeptIDsAllowed=*"
    


    But it does not work the Names resulting from the Get-CMDevide are not passed to the Get-ChildItem.

    I have an error

    Get-ChildItem : Cannot find path '\\$_.Name\C$\Program Files\CCSI\800\8001\OBIXConfig\defaults.ini' because it does not exist.
    At line:4 char:1
    + Get-ChildItem "\\$Name\C$\Program Files\CCSI\800\8001\OBIXConfig\defa ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (\\$_.Name\C$\Pr...ig\defaults.ini:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    

    How to pass the machine name(s) issued from the Get-CMDevice to the UNC path in Get-ChilItem?

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL

    Monday, November 11, 2019 9:35 PM

Answers

  • Here's one way:

    get-childitem <your-criteria> |
        Get-content | 
            foreach {
                if ($_ -like "DeptIDsAllowed=*"){
                    Write-Host "Found it!"
                }
            }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by jrv Monday, November 11, 2019 10:30 PM
    • Marked as answer by Felyjos Monday, November 11, 2019 10:52 PM
    Monday, November 11, 2019 10:23 PM

All replies

  • I think you need to learn PowerShell as most of the code is just bad guessing.

    Get-CMDevice -CollectionID UCP0088F | 
        ForEach-Object{ 
            Get-ChildItem "\\$($_.Name)\C$\Program Files\CCSI\800\8001\OBIXConfig"
        }

    It is unclear what you actually want since the code is pretty indecipherable.

    "select-string" does not use wildcards and is not a filter.  It takes either an exact match or a RegEx pattern. 

    When in doubt read the help for the CmdLets.  It will save you time and confusion.


    \_(ツ)_/

    Monday, November 11, 2019 9:52 PM
  • Thank you for this.

    I am looking for the contents of the DeptIDsAllowed in the Default.ini file for the machines within the collection UCP0088F.

    example of default.ini file:

    ;$Id: defaults.ini 5089 2015-09-28 16:04:36Z brad $
    
    [Main]
    DeptIDsAllowed=SANTA MONICA_SM-OBIX-TOP
    ;The DeptIDsAllowed is should be a comma seperated list for all logon depts for this client:
    ;Example: Hosp1_BS,Hosp2_BS,Hosp3_BS,etc...
    
    
    [ObixLauncher]
    FrameX=0
    FrameY=0
    FrameCX=1
    FrameDX=1
    FrameCY=72
    FrameDY=100
    ObixDocPath=\\vrpobixfmdm1.ad\OBIXConfig\References\8001

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL


    • Edited by Felyjos Monday, November 11, 2019 10:09 PM
    Monday, November 11, 2019 10:09 PM
  • Here's one way:

    get-childitem <your-criteria> |
        Get-content | 
            foreach {
                if ($_ -like "DeptIDsAllowed=*"){
                    Write-Host "Found it!"
                }
            }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by jrv Monday, November 11, 2019 10:30 PM
    • Marked as answer by Felyjos Monday, November 11, 2019 10:52 PM
    Monday, November 11, 2019 10:23 PM
  • Here's one way:

    get-childitem <your-criteria> |
        Get-content | 
            foreach {
                if ($_ -like "DeptIDsAllowed=*"){
                    Write-Host "Found it!"
                }
            }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Hello,

    Get-CMDevice -CollectionID UCP00AEB | 
        ForEach-Object{ 
            Get-ChildItem "\\$($_.Name)\C$\Program Files\CCSI\800\8001\OBIXConfig\default.ini" |
        Get-content | 
            foreach {
                if ($_ -like "DeptIDsAllowed=*"){
                    Write-Host "Found it!"
                }
            }
        }


    Get-ChildItem : Cannot find path '\\CNSM2LD2528A\C$\Program Files\CCSI\800\8001\OBIXConfig\default.ini' because it does not exist.

    The path exists... is accessible...

    Cannot find path '\\CNSM2LD2528A\C$\Program Files\CCSI\800\8001\OBIXConfig\default.ini'

    Reviewing why this message as the security looks okay and the access is 

    Several articles talking about issues between UNC and PowerShell..

    https://stackoverflow.com/questions/42512766/get-childitem-cannot-find-path-because-it-does-not-exist

    https://stackoverflow.com/questions/23574653/running-get-childitem-on-unc-path-works-in-powershell-but-not-in-powershell-run

    If I remove the quotes as suggested in the articles, I am getting another error:

    Get-CMDevice -CollectionID UCP00AEB | 
        ForEach-Object{ 
            Get-ChildItem \\$($_.Name)\C$\Program Files\CCSI\800\8001\OBIXConfig\default.ini |
        Get-content | 
            foreach {
                if ($_ -like "DeptIDsAllowed=*"){
                    Write-Host "Found it!"
                }
            }
        }
    PS UCP:\> C:\Source Files\SCCM 2007 Tools\ADK\Collect Field Content.ps1
    Get-ChildItem : Cannot call method. The provider does not support the use of filters.
    At C:\Source Files\SCCM 2007 Tools\ADK\Collect Field Content.ps1:3 char:9
    +         Get-ChildItem \\$($_.Name)\C$\Program Files\CCSI\800\8001\OBI ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotImplemented: (:) [Get-ChildItem], PSNotSupportedException
        + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.GetChildItemCommand

    Trying a simple powershell hardcoded:

    Get-CMDevice -CollectionID UCP00AEB | ForEach-Object{ Get-WmiObject -ComputerName 'CNSM2LD2528A' -Class Win32_Share Get-ChildItem "\\CNSM2LD1528\C$" | Get-content | foreach { if ($_ -like "DeptIDsAllowed=*"){ Write-Host "Found it!" } } }

    this is giving the same error even the share is displayed by the Get-WmiObject... PS UCP:\> C:\Source Files\SCCM 2007 Tools\ADK\Collect Field Content.ps1 Name Path Description ---- ---- ----------- ADMIN$ C:\WINDOWS Remote Admin C$ C:\ Default share IPC$ Remote IPC print$ C:\WINDOWS\system32\spool\drivers Printer Drivers Get-ChildItem : Cannot find path '\\CNSM2LD1528\C$' because it does not exist. At C:\Source Files\SCCM 2007 Tools\ADK\Collect Field Content.ps1:3 char:9 + Get-ChildItem "\\CNSM2LD1528\C$" | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (\\CNSM2LD1528\C$:String) [Get-


    Verifying the permissions as well... Explorer has access but not PowerShell!!!

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL







    • Edited by Felyjos Tuesday, November 12, 2019 2:40 PM
    Tuesday, November 12, 2019 12:14 AM