ISE vs powershell - 'ScriptBlock'. The argument is null

This topic contains 1 reply, has 1 voice, and was last updated by  Mark 3 weeks ago.

  • Author
    Posts
  • #103462

    Mark
    Participant

    Hi guys

    first time poster so please excuse any bad formatting!!

    really strange one – i have a very simple script:-

    Install-Module -Name SpeculationControl -Force

    $vms = Get-ADComputer -Filter {(operatingsystem -like "*Server*") -and (enabled -eq $true)} -SearchBase "dc=xxx,dc=com" | Select Name

    $result = foreach ($vm in $vms) {Invoke-Command -ComputerName $vm.name ${function:Get-SpeculationControlSettings}}

    i currently can run this in an ISE window and it goes through all vm's successfully but when i go to run in powershell i get the below error:-

    Invoke-Command : Cannot validate argument on parameter 'ScriptBlock'. The argument is null. Provide a valid value for the argument, and then try running
    the command again.
    At line:1 char:72
    + ... nd -ComputerName $vm.name ${function:Get-SpeculationControlSettings}}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

    even more strage is when i open up another ISE program i get the above error.

    im sure something very simple...please help

    thanks in advance
    mark

  • #103469

    Mark
    Participant

    ignore me – id not imported active-directory module...doh

You must be logged in to reply to this topic.