function Disable-AutoRun { $item = Get-Item ` "REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\AutoRun.inf" ` -ErrorAction SilentlyContinue if (-not $item) { $item = New-Item "REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\AutoRun.inf" } Set-ItemProperty $item.PSPath "(default)" "@SYS:DoesNotExist" } function Enable-AutoRun { Remove-Item "REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\AutoRun.inf" -Force } Disable-AutoRun # Enable-AutoRun
$path ='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer' Set-ItemProperty $path -Name NoDriveTypeAutorun -Type DWord -Value 0xFF
Reference: http://stackoverflow.com/questions/14564380/how-to-disable-autorun-for-all-drives