box_l Posted February 23, 2011 Posted February 23, 2011 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
box_l Posted February 23, 2011 Author Posted February 23, 2011 Perfect! Many thanks for the speedy answer. BoX
jamesb Posted February 23, 2011 Posted February 23, 2011 Just don't ask how many times I've been caught out by the difference between 0 and null.
mac_shinobi Posted February 23, 2011 Posted February 23, 2011 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 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now