-3
I would like to exchange some practical ideas with you to accomplish an achievement: Create a script for Windows that checks the Serial Number of a USB stick and can thus allow or deny that it mounts:
So far, I have the following:
#CAPTURA SERIAL NUMBER
$serial = ((Get-Physicaldisk|Select SerialNumber,BusType|findstr /L USB)| %{"$($_.Split('USB'))"})
#CONSULTA SE O SERIAL FOI CADASTRADO NO SISTEMA
iwr http://FORMULARIO_WEB_COM_SERIAIS_DE_PENDRIVES_CADASTRADOS.html -OutFile C:\Users\%USER%\AppData\Local\serie.txt
ForEach ($value in $serial){
$compara = (Select-String -Path C:\Users\%USER%\AppData\Local\serie.txt “[$value]” -Quiet)
$value
$compara
if ($compara = "True"){
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR /v Start /t REG_DWORD /D 3 /f
}
else{
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR /v Start /t REG_DWORD /D 4 /f
}
}
The serie.txt file contains strings with serial number of disks allowed and as it is updated in the WEB form continuously, it updates the list.
In the above script, the $compare variable should compare the serial of the connected device via USB and then give the value True or False. But it only gives True, even though the value of the serial String is not in the file serie.txt.
If I do
Select-String -Path C:\Users\admin\AppData\Local\serie.txt “123456” -Quiet
and "123456" is in the file serie.txt, the value is True!
And then people suggest to me?
To avoid too long discussion in the comments the conversation was moved to the chat and can proceed by the link provided. On the question, can [Edit] and provide a [mcve] of the party with problems to reconsider the posting. To understand what kind of question serves the site and, consequently, avoid closures and negativities worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco