Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Call function with parameters invoke -command powershell

$
0
0
                  
You cannot vote on your own post

hey Guys,

Need help in invoking function remotely I get error invalid function. let me know what is missing

error message

nvoke-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:91
+ ...   -ScriptBlock ${function:EnableADBA } -ArgumentList $adbakey
+                    ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParameterBind
   ingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.InvokeCommandCommand


$LocalAdminCredentialToUse = Get-Credential
 function EnableADBA
{
    param($Key)
    # Need to check the OS version to see if Active Directory is enabled.
    $OSVersion = [System.Environment]::OSVersion.Version
    if ($OSVersion.Major -gt 6 -or (($OSVersion.Major -eq 6) -and ($OSVersion.Minor -ge 2)))
    {
       write-host "Enabling ADBA"
        slmgr.vbs /ad-activation-online  $Key "WinVLK"
       write-host "Enabled ADBA"
    }
    else
    {
       write-host "ADBA could not be enabled, as we are not running on Windows Server  2012 or greater."

    }
}

$fqdn = Get-ADDomain -Server "pods975105007.test.net" |select -ExpandProperty PDCEmulator
$adbakey = "abcde-wxyz-rzsd-4b26"
Invoke-Command -ComputerName $fqdn -Credential  $LocalAdminCredentialToUse   -ScriptBlock ${function:EnableADBA  } -ArgumentList $adbakey

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>