I am getting the following error when I run the function below:
Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. At C:\Users\usernameone\Desktop\script.ps1:16 char:29 + Invoke-Command -ComputerName <<<< $_ -ScriptBlock $s -Credential $cred + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
$username = "username"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$_="192.168.10.4"
function test{
$s = $ExecutionContext.InvokeCommand.NewScriptBlock("mkdir C:\'Documents and Settings'\username\Desktop\Testfolder")
Invoke-Command -ComputerName $_ -ScriptBlock $s -Credential $cred
}
Do you have any ideas as to what I've done wrong?