Brandon Mac
asked on
Get bitlocker keys remotely
Manage Bitlocker keys for enterprise network, gather the keys and log any computers offline that resulted in not getting bitlocker key for that computer
below script is not working correctly for multiple computers to be checked for online connectivity write log, get bitlocker or else write log stating computername of machine that is offline, I don't know where I went wrong with my function for the log because all thats happening is log file shows date time stamp and nothing else and I'm not getting any other keys
function log($string){
write-host $string
$timestamp = (get-date -format dd-mm-yyyy) + "|" + (get-date -format HHMMsstt)
$computers = get-content -path '\\computername\c$\users\a dmin\deskt op\scripts \Laptops.t xt'
FOREACH($COMPUTER IN $COMPUTERS){
if(Test-Connection -ComputerName $computer -count 1 -quiet){
log "$computer is online getting bitlocker key"
manage-bde -protectors -get c: -computername $computer > "\\computername\c$\users\a dmin\deskt op\bitlock er\$comput er.txt"
}
else{
$logfile = "\\computername\c$\users\a dmin\deskt op\scripts \logs\devi cesoffline .txt"
log "$computer is Offline"
$timestamp + " " + $string | out-file -FilePath $logfile -Append -force
}
}
}
below script is not working correctly for multiple computers to be checked for online connectivity write log, get bitlocker or else write log stating computername of machine that is offline, I don't know where I went wrong with my function for the log because all thats happening is log file shows date time stamp and nothing else and I'm not getting any other keys
function log($string){
write-host $string
$timestamp = (get-date -format dd-mm-yyyy) + "|" + (get-date -format HHMMsstt)
$computers = get-content -path '\\computername\c$\users\a
FOREACH($COMPUTER IN $COMPUTERS){
if(Test-Connection -ComputerName $computer -count 1 -quiet){
log "$computer is online getting bitlocker key"
manage-bde -protectors -get c: -computername $computer > "\\computername\c$\users\a
}
else{
$logfile = "\\computername\c$\users\a
log "$computer is Offline"
$timestamp + " " + $string | out-file -FilePath $logfile -Append -force
}
}
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Yes...lol it looks like I didn't catch that when I copied it. I must have had another verison on the clipboard when I hit paste into the window. Thanks for taking the time to look at this and help me out. Also I appreicate your input about other methods as well as I learn PS and the ways of automating tasks its good to find someone willing to share other ways that may work better or more efficient. Thanks