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)
$username = 'tst\user-ad'
$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 Global `
-Path $Using:path `
-GroupCategory Security
} -authentication credssp -credential $cred
the first error that appeared is first error
after that i took my code and copied to the newly created file and it worked work in another file
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 work/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
my workaround was that I renamed the test.ps1 file to the name I needed, and deleted the non-working file, and after that everything worked for me, while I did not change the contents of the file
thanks!