none
PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

    Question

  • Hi all,

    I have new to PS and trying to run a powershell command, which is giving me error. Please let me know what I am missing here. I am having trouble to run the script to create folders and collections



    PS E:\> dir SCCMTools\powershellscripts\createfoldersandcollections.ps1> Set-ExecutionPolicy RemoteSigned
    Get-ChildItem : A positional parameter cannot be found that accepts argument 'RemoteSigned'.
    At line:1 char:4
    + dir <<<<  SCCMTools\powershellscripts\createfoldersandcollections.ps1> Set-ExecutionPolicy RemoteSigned
        + CategoryInfo          : InvalidArgument: ( :)[Get-ChildItem], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

    PS E:\>

    ----
    I think the issue with the .ps1 but I am not sure what will be the work around.
    When I run this without .ps1, it gives me the below error


    PS E:\SCCMTools> dir powershellscripts\CreateFoldersAndCollections
    Get-ChildItem : Cannot find path 'E:\SCCMTools\powershellscripts\CreateFoldersAndCollections' because it does not exist
    .
    At line:1 char:4
    + dir <<<< powershellscripts\CreateFoldersAndCollections
    + CategoryInfo : ObjectNotFound: (E:\SCCMTools\po...sAndCollections:String) [Get-ChildItem], ItemNotFound
    Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

    Sunday, March 3, 2013 12:17 AM

All replies

  • First of all dir is used to show the content of a folder not to execute a script.

    When you try to dir powershellscripts\CreateFoldersAndCollections it thinks that CreateFoldersAndCollections is a folder that it should display the content for. However this a file, and there is no folder, therefore it cannot find the path you defined.

    If you wan to run a PowerShell script, within the console you can either just type in the full path
    E:\SCCMTools\powershellscripts\createfoldersandcollections.ps1

    Or you can type in the relative path, ex. if you are in E:\SCCMTools:
    .\powershellscripts\createfoldersandcollections.ps1

    Also if you want to use Functions/Variables defined in this script afterwards, you should run it with a period in front, like this:
    . E:\SCCMTools\powershellscripts\createfoldersandcollections.ps1

    If you need to run the script with another ExecutionPolicy, you will either have to run the command Set-ExecutionPolicy beforehand, or run the script in a new powershell session, like this:
    Powershell.exe -ExecutionPolicy RemoteSigned E:\SCCMTools\powershellscripts\createfoldersandcollections.ps1


    Best Regards
    Claus Codam
    Consultant, Developer
    Coretech - Blog


    Sunday, March 3, 2013 2:56 AM
  • Nice explanation, Claus - one comment on your second paragraph.

    the line dir powershellscripts\CreateFoldersAndCollections doesn't work because there is nothing with that name found - the file-vs-folder doesn't matter because of the weird get-childitem semantics, where a file is treated as a container for itself.

    Monday, March 4, 2013 12:21 AM
  • You are absolutely right Alex, I'm sorry that I weren't that clear.

    As you said, Get-ChildItem will work on both folders and files, all I meant was that without the file extension he was actually looking for a folder instead of the file. Then again it could just be a file without an extension :)


    Best Regards
    Claus Codam
    Consultant, Developer
    Coretech - Blog

    Monday, March 4, 2013 12:56 AM
  • First of all, many thanks for your reply.

    I am new to PS and you can see I am keep trying to run couple of PS command.

    I am tring to follow this guide http://www.windows-noob.com/forums/index.php?/topic/6799-using-system-center-2012-configuration-manager-part-9-deploying-monthly-updates/without any success. I am not sure, why I am having different result.

    Windows PowerShell

    Copyright (C) 2009 Microsoft Corporation. All rights reserved.

    PS C:\Windows\system32> cd 'E:\SCCMTools\PowershellScripts\createfoldersandcollections'

    Set-Location : Cannot find path 'E:\SCCMTools\PowershellScripts\createfoldersandcollections' because it does not exist.

    At line:1 char:3

    + cd <<<<  'E:\SCCMTools\PowershellScripts\createfoldersandcollections'

        + CategoryInfo          : ObjectNotFound: (E:\SCCMTools\Po...sandcollections:String) [Set-Location], ItemNotFoundE

       xception

        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

    PS C:\Windows\system32> cd E:\SCCMTools\PowershellScripts\createfoldersandcollections.ps1

    Set-Location : Cannot find path 'E:\SCCMTools\PowershellScripts\createfoldersandcollections.ps1' because it does not ex

    ist.

    At line:1 char:3

    + cd <<<<  E:\SCCMTools\PowershellScripts\createfoldersandcollections.ps1

        + CategoryInfo          : ObjectNotFound: (E:\SCCMTools\Po...collections.ps1:String) [Set-Location], ItemNotFoundE

       xception

        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

    PS C:\Windows\system32> cd e:\

    PS E:\> SCCMtools\PowershellScripts\createfoldersandcollections

    The term 'SCCMtools\PowershellScripts\createfoldersandcollections' is not recognized as the name of a cmdlet, function,

     script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is c

    orrect and try again.

    At line:1 char:56

    + SCCMtools\PowershellScripts\createfoldersandcollections <<<<

        + CategoryInfo          : ObjectNotFound: (SCCMtools\Power...sandcollections:String) [], CommandNotFoundException

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\> dir sccmtools

        Directory: E:\sccmtools

    Mode                LastWriteTime     Length Name

    ----                -------------     ------ ----

    d----         8/11/2012  10:43 AM            Monitoring pack for power management

    d----         3/03/2013   1:09 PM            powershell scripts

    d----        12/12/2012   5:11 PM            Report Viewer Redistributable

    -a---        13/12/2012   5:39 PM    1561354 SCCM installation.docx

    PS E:\> powershell scripts\createfoldersandcollections

    The term 'scripts\createfoldersandcollections' is not recognized as the name of a cmdlet, function, script file, or ope

    rable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

    .

    At line:1 char:36

    + scripts\createfoldersandcollections <<<<

        + CategoryInfo          : ObjectNotFound: (scripts\createfoldersandcollections:String) [], CommandNotFoundExceptio

       n

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\> 'powershell scripts\createfoldersandcollections'

    powershell scripts\createfoldersandcollections

    PS E:\> Set-ExecutionPolicy RemoteSigned

    Execution Policy Change

    The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose

    you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution

    policy?

    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

    PS E:\> "Y"

    Y

    PS E:\> .\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Updates.xml

    The term '.\CreateFoldersAndCollections.ps1' is not recognized as the name of a cmdlet, function, script file, or opera

    ble program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    At line:1 char:34

    + .\CreateFoldersAndCollections.ps1 <<<<  .\FolderAndCollections_Software_Updates.xml

        + CategoryInfo          : ObjectNotFound: (.\CreateFoldersAndCollections.ps1:String) [], CommandNotFoundException

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\>

    PS E:\> 'powershell scripts\createfoldersandcollections'>.\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Softwa

    re_Updates.xml

    Unexpected token '.\FolderAndCollections_Software_Updates.xml' in expression or statement.

    At line:1 char:127

    + 'powershell scripts\createfoldersandcollections'>.\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Up

    dates.xml <<<<

        + CategoryInfo          : ParserError: (.\FolderAndColl...are_Updates.xml:String) [], ParentContainsErrorRecordExc

       eption

        + FullyQualifiedErrorId : UnexpectedToken

    PS E:\>

    PS E:\> powershell scripts\createfoldersandcollections> .\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Softwar

    e_Updates.xml

    The term 'scripts\createfoldersandcollections>' is not recognized as the name of a cmdlet, function, script file, or op

    erable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try agai

    n.

    At line:1 char:37

    + scripts\createfoldersandcollections> <<<<  .\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Updates.

    xml

        + CategoryInfo          : ObjectNotFound: (scripts\createfoldersandcollections>:String) [], CommandNotFoundExcepti

       on

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\> .\CreateFoldersAndCollections .\FolderAndCollections_Software_Updates

    The term '.\CreateFoldersAndCollections' is not recognized as the name of a cmdlet, function, script file, or operable

    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    At line:1 char:30

    + .\CreateFoldersAndCollections <<<<  .\FolderAndCollections_Software_Updates

        + CategoryInfo          : ObjectNotFound: (.\CreateFoldersAndCollections:String) [], CommandNotFoundException

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\> '.\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Updates.xml'

    .\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Updates.xml

    PS E:\>

    PS E:\> .\CreateFoldersAndCollections .\FolderAndCollections_Software_Updates.xml

    The term '.\CreateFoldersAndCollections' is not recognized as the name of a cmdlet, function, script file, or operable

    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    At line:1 char:30

    + .\CreateFoldersAndCollections <<<<  .\FolderAndCollections_Software_Updates.xml

        + CategoryInfo          : ObjectNotFound: (.\CreateFoldersAndCollections:String) [], CommandNotFoundException

        + FullyQualifiedErrorId : CommandNotFoundException

    PS E:\>

    ------------------------


    • Edited by mkhan100 Wednesday, March 6, 2013 2:17 AM
    Wednesday, March 6, 2013 2:15 AM
  • Hi,

    Please try below commands:

    PS C:\Windows\system32> cd E:\SCCMTools

    Then type:

    .\PowershellScripts\createfoldersandcollections.ps1

    Regards,

    Yan Li


    Cataleya Li
    TechNet Community Support

    Wednesday, March 6, 2013 8:17 AM
    Moderator
  • I have managed to make the command you are suggesting to work

    PS E:\> 'powershell scripts\createfoldersandcollections'

    powershell scripts\createfoldersandcollections

    But I cannot make the last command to work. According to the guide(http://www.windows-noob.com/forums/index.php?/topic/6799-using-system-center-2012-configuration-manager-part-9-deploying-monthly-updates/), this command, suppose to run

    .\CreateFoldersAndCollections.ps1 .\FolderAndCollections_Software_Updates.xml

    As you can see from my previous reply, that I am getting errors in all combination of that command but when I try the last combination, nothing is happening. It just sit there


    PS E:\> '.\CreateFoldersAndCollections.ps1' '.\FolderAndCollections_Software_Updates.xml' 

    Wednesday, March 6, 2013 10:56 PM