I was writing this code to capture newly created AD's samaccountname and make a homefolder for it ! im facing this issue -
$ADServer= 'xyz'
$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 1
New-Item -ItemType Directory -Path "\\abc\$c"
this is showing error - illegal characters in string, how can I create the folder of the same thing I captured in $c ?
$ccontain? I suspect it is currently an object, therefore you may need to select the specific property for this to work$c? If it is displayed in a table show what the columns are.\\abc\xyzmight not be sufficient here if you're having this issue. You need to show exactly what these variables contain. Does it work if you manually run theNew-Itemcommand?