Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

A client wants a very basic way of finding the owner of lost USB sticks.

 

I have written this powershell script

 

#get serial from usb

$serial = gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | select-string USBSTOR | foreach{$_.tostring().split("\\")[8].split("&")[0]}

#cat txt file for existing serial and if exist display name

$exists = cat .\somefile.txt | select-string $serial

# not equal 0

if ($exists -ne 0) 
{
echo $exists
}
else
{
$name = read-host "please enter USB owner name"

echo "$serial $name" >> ./somefile.txt
}

 

which does everthing but the "Else" part.

 

Any ideas?

 

BoX

Posted
Just don't ask how many times I've been caught out by the difference between 0 and null. :)

 

Difference is one puts you into invalid memory and the other one works :D

 

I was going to suggest also trying or using the equivelant of Select Case or Switch ( depending on the language used ), not sure what powershell uses, I presume Switch :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...