I have a script to add an AD group.
For a while, it worked out correctly, and then stopped working with strange errors
param($name, $path, $groupScope)
$username = 'tst\ad-user'
$encryptedStringPwd = Get-Content C:\Scripts\pwd\DNSpwd.txt
$password = ConvertTo-SecureString $encryptedStringPwd
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
Invoke-Command -ComputerName . -ScriptBlock {
New-ADGroup `
-Name $Using:name `
-SamAccountName $Using:name `
-GroupScope $Using:groupScope`
-Path $Using:path `
-GroupCategory Security
} -authentication credssp -credential $cred
the first error that appeared is
after that i took my code and copied to the newly created file and it worked
after that I deleted the original non-working script and created the same one, the script did not work at first, after a couple of starts, it worked, but at the same time continued to write an error
can someone help explain what it is and why it works like that
I will repeat once again that before that everything worked correctly and I am sure that no changes were made to the script
thanks!