I need to adjust the below script to get Bitlocker status to a text file that should have the computer name as for its filename. So for a PC named Station10 the script would output a text file called Station10_enabled.txt
. Or, if Bitlocker is disabled, it would create a file called Station10_disabled.txt
.
I have below code, which seems to make sense, but is not working.
The code produces the error "Can not use parentheses when calling a sub
", how can I fix that?
I also fear once the code runs the %computername% variable will not work or create a syntax error, but I can't test because of above issue.
If anyone out there knows how to gracefully handle what I am trying to do, please help.
strComputer = "."
Set objShell = CreateObject("Wscript.Shell")
strEnvSysDrive = objShell.ExpandEnvironmentStrings("%SystemDrive%")
Set objWMIServiceBit = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2 \Security\MicrosoftVolumeEncryption")
Set colItems = objWMIServiceBit.ExecQuery("SELECT * FROM Win32_EncryptableVolume",,48)
For Each objItem in colItems
If objItem.DriveLetter = strEnvSysDrive Then
strDeviceC = objItem.DeviceID
DriveC = "Win32_EncryptableVolume.DeviceID='"&strDeviceC&"'"
Set objOutParams = objWMIServiceBit.ExecMethod(DriveC, "GetProtectionStatus")
If objOutParams.ProtectionStatus = "1" Then
My.Computer.FileSystem.WriteAllText("C:\cos\.txt","Bitlocker is enabled.",True)
Else
My.Computer.FileSystem.WriteAllText("C:\cos\test.txt","Bitlocker is disabled.",True)
End if
End If
Next