get-job state blocked

Welcome Forums General PowerShell Q&A get-job state blocked

This topic contains 7 replies, has 4 voices, and was last updated by

 
Participant
3 years, 6 months ago.

  • Author
    Posts
  • #25583

    Participant
    Points: 0
    Rank: Member

    Hello everyone I'm trying to build a script in part of the script it will search for a specific filename in drive and will delete it if found I created a job
    start-job -scriptblock { Get-ChildItem d:\ -Include $filename -Recurse -Force | Remove-Item }
    any idea what could be missing I checked technet they only mentioned that blocked means it's waiting user intervention any help please

    Best

  • #25584

    Member
    Points: 0
    Rank: Member

    Best guess, you've got a directory that's matching your $filename as well, the directory contains subfolders or files, and you haven't used the -Recurse parameter, which results in a prompt for the user.

    If you only want this to target files rather than directories, you can do this one of two ways:

    # On Powershell 3.0 or later, just use the -File switch to GetChildItem:
    Get-ChildItem d:\ -Include $filename -Recurse -Force -File | Remove-Item 
    
    # In PowerShell 2.0, filter with Where-Object
    Get-ChildItem d:\ -Include $filename -Recurse -Force | Where-Object { -not $_.PSIsContainer } | Remove-Item 
    
  • #25585

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    You may need to add

    -force -confirm:$false

    To Remove-Item, also,

  • #25586

    Participant
    Points: 0
    Rank: Member

    start-job -scriptblock { Get-ChildItem -path e:\ -Include example.txt -Recurse -Force -confirm:$false | Remove-Item -force -confirm:$false }
    the state now failed I created a small virtual drive e:\ and copied many folders in it and in each folder contains example.txt just for texting purpose but nothing happend and state is failed

  • #25587

    Member
    Points: 0
    Rank: Member

    Try running Receive-Job, to see what the errors were.

  • #25588

    Participant
    Points: 0
    Rank: Member

    PS E:\> get-job -name job36 | receive-job -keep
    A parameter cannot be found that matches parameter name 'confirm'.
    + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    + PSComputerName : localhost

  • #25589

    Member
    Points: 0
    Rank: Member

    Ah, that's only on Remove-Item, not Get-ChildItem.

  • #25590

    Participant
    Points: 303
    Helping Hand
    Rank: Contributor

    Remove-Item may need the switch, not Get-ChildItem:

    start-job -scriptblock { Get-ChildItem -path e:\ -Include example.txt -Recurse  | Remove-Item -force -confirm:$false }
    

The topic ‘get-job state blocked’ is closed to new replies.