<# Focus purely on Windows 7#> $line_array = @() $multi_array = @() [hashtable]$my_hash = @{} $Sender_IP = $NULL $Win32OS = $NULL $Build = $NULL $folder = $NULL $SysDrv = $NULL foreach ($i in $args){ $line_array+= $i.split(" ") } foreach ($j in $line_array){ $multi_array += ,@($j.split("=")) } foreach ($k in $multi_array){ $my_hash.add($k[0],$k[1]) } $Sender_IP = $my_hash.Get_Item("sender-email") try{ Test-Connection $Sender_IP -count 1 -ErrorAction Stop | out-null } catch [Exception] { $userID = "userID=CannotPing" return $userID } try{ $OS = (Get-WmiObject Win32_OperatingSystem -ComputerName $Sender_IP -ErrorAction Stop).Name } catch [Exception]{ $userID = "userID=CannotAuthenticate" return $userID } try{ $Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Sender_IP -ErrorAction Stop } catch [Exception]{ $userID = "userID=CannotAuthenticate" return $userID } $SysDrv = $Win32OS.SystemDrive $SysDrv = $SysDrv.Replace(":","$") $ProfDrv = "\\" + $Sender_IP + "\" + $SysDrv $ProfLoc = Join-Path -Path $ProfDrv -ChildPath "Users" if (!(Test-Path $ProfLoc)){ $ProfLoc = Join-Path -Path $ProfDrv -ChildPath "Documents and Settings" } try{ $userID = Get-ChildItem $ProfLoc | ? { $_.PsIsContainer} | Sort LastWriteTime -Descending | Select -expand Name -First 1 $userID = "userID="+$userID }catch [Exception] { $userID = "userID=CannotFindLastUser" return $userID } if ($userID -eq "userID=All Users"){ $userID = (get-wmiobject win32_computersystem -computer $Sender_IP).UserName $userID = "userID="+$userID return $userID } else{ return $userID }