SetSPN using powershell to run CMD commands -
i trying make script runs cmd command set spn: in effect of each item in list run setspn -s (name of spn) domain\service account have hard time running command line need able change (name of spn go though list)
$list = get-content c:\users\mycomputer\desktop\lists.txt foreach($pn in $list){ $semper_fi = @' cmd.exe /c setspn –s "some spn name\corp.com:1000" corporatedomain\serviceaccount1 '@ invoke-expression -command:$semper_fi }
-s suppose in ad , if name doesn't exist adds or otherwise moves next item , on. gives me error: + categoryinfo : notspecified: (unknown paramet...eck usage.:string) [], remoteexception + fullyqualifiederrorid : nativecommanderror
so every name in list: (check see if not in ad add this) (this spn) setspn -s serversql1/pop1.company.com:2500
(under service account) domain\service100
and keep going until done.
i think issue syntax need drop :
invoke expression not called in cmdlet specification. can put in name list replacing "some spn name" $($pn)
.
however can clean loop if drop invoke-expression entirely , use call operator &
instead. in case replace entirety of inside of foreach loop with
& cmd.exe /c setspn –s $pn\corp.com:1000 corporatedomain\serviceaccount1
i'm 90% should work don't have test environment can muck around spn's available right can't confirm, if kind of error please let me know , try , sort out.
Comments
Post a Comment