Creation of home drive as soon as its AD is created through eventlog method


i writing code - 

$adserver = 'xyz'  $a = (get-eventlog security -computername $adserver -after (get-date).addhours(-24) | where-object { $_.eventid -eq 4720}).count  if($a -ge 1)  {  	  $c = get-eventlog security -computername $adserver -after (get-date).addhours(-24) | where-object { $_.eventid -eq 4720 -and $_.message -match "sam account name:\s+(.*)"} | foreach-object { $matches[1] } | select-object -first 50    foreach($b in $c)  {  new-item -itemtype directory -path "\\abc\$b"  }	  }  else  {  exit-pssession  }  

what want search ad user created event(event id - 4720) , straightaway fetch samaccountname event , create home drive in desired path. script can run every 24 hours ensure no user left.
way automated.

getting error saying "new - item : illegal characters in path"
, else block doesnt seem working..

any scripting gurus, pls suggest changes or @ right path?
or - bad???

attach task event 4720 , export task. edit xml file , add following eventtrigger node:

<valuequeries>   <value name="samaccountname">event/eventdata/data[@name='samaccountname']</value> </valuequeries>

save changes , recreate task using xml file described here.

change action of task to:

program/script: powershell.exe
add arguments: .\triggerscript.ps1 -samaccountname $(samaccountname)

create triggerscript.ps1 , make sure first line:

param($samaccountname)

now can use $samaccountname create folder new-item.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group