Przyszła lista kont do zablokowania, oczywiście w formacie .xls. Jako ze konta powinny być blokowane jak najszybciej, a osoba która sie tym zajmuje ma dzisiaj wolne, na mnie spadł ten obowiązek.
Na początku trzeba było dodać nagłówki do kolumn w excelu, a następnie wyeksportować wynik do pliku .csv.
Następnie w ciągu 3h napisałem taki skrypcik
#configuration$lista = Import-Csv blokada.csv$studentOU="OU=studenci,DC=pjwstk,DC=edu,DC=pl"$data=get-date -format g$comment="[blocked "+$data+"by PeKi script(dziekanat)]"$logname = "log";$logname += get-date -format "yyyyMMdd_hhmmss";$logname +=".log";#processing$log=@();$notFoundLog=@();$alreadyDisabled=@();$l=0$k=0;foreach ($user in $lista){$l++;$stud="LDAP://CN=s"+$user.Album+","+$studentOU;if ([DirectoryServices.DirectoryEntry]::Exists($stud)){$de = new-object DirectoryServices.DirectoryEntry($stud);$uac=$de.userAccountControl;$iuac=[int]$uac.toString();if (($iuac -band 2) -eq 0 ){$iuac+=2;$deLastName=$de.InvokeGet("LastName");$k++;$deFirstName=$de.InvokeGet("FirstName");$deCommonName=$de.InvokeGet("cn");$deComment=$de.InvokeGet("comment");$deDescription=$de.InvokeGet("Description");$date = get-date -format g;$deComment=$deComment+$comment;$deDescription=$comment+$deDescription;$log+= $deCommonName+" "+$deLastName +" " +$deFirstName +" ";$de.InvokeSet("comment",[string]$deComment);$de.InvokeSet("Description",[string]$deDescription);$de.InvokeSet("userAccountControl",[int]$iuac);$de.CommitChanges();$de.close();}else{$alreadyDisabled+= "disabled:"+$user.Album +"uac: " +$uac;}}else {$notFoundLog+= "not found:"+$user.Album +" cn: " +$stud ;}}#outputecho "dobrych"| out-file $logname -Append$log| out-file $logname -Appendecho "zlych"| out-file $logname -Append$notFoundLog| out-file $logname -Append$alreadyDisabled| out-file $logname -Appendecho "prztworzonych" $k " z " $l| out-file $logname -Appendwrite-host "dobrych";$logwrite-host "zlych";$notFoundLog$alreadyDisabledwrite-host "prztworzonych" $k " z " $l;
Z ciekawszych rzeczy w tym skrypcie widać:
Remember Me