Skip to content

Instantly share code, notes, and snippets.

View mczerniawski's full-sized avatar

mczerniawski mczerniawski

View GitHub Profile
$VMName = 'SomeVM'
$GUID = Get-VM $VMName | Select-Object -ExpandProperty id | Select-Object -ExpandProperty Guid
$processID = Get-Process vmwp -IncludeUserName | Where-Object {$_.Username -match $GUID} | Select-Object -ExpandProperty ID
Get-ADComputer -Filter * -SearchBase 'OU=Servers,OU=Computers,DC=contoso,DC=com' -Properties 'DNSHostName','lastLogon','lastlogontimestamp','operatingSystem','operatingSystemVersion','whenChanged','whenCreated' | Select-Object 'DNSHostName',
@{name='lastLogon';e={[datetime]::FromFileTime($PSItem.'lastLogon') }},
@{name='lastLogontimestamp';e={[datetime]::FromFileTime($PSItem.'lastLogontimestamp') }},
'operatingSystem','operatingSystemVersion','whenCreated','whenChanged','DistinguishedName',
@{name='InUse';e={''}},
@{name='CurrentAccessList';e={''}},
@{name='Applications';e={''}},
@{name='SystemUpdate';e={''}},
@{name='PM';e={''}},
@{name='TO';e={''}}
Get-ADComputer -Filter * -SearchBase 'OU=Servers,OU=Computers,DC=contoso,DC=com' -properties 'operatingSystem','whenCreated','whenChanged'
$AdComputerFilter = 'DNSHostName','lastLogon','lastlogontimestamp','operatingSystem','operatingSystemVersion','whenChanged','whenCreated'
$SelectObjectFilter = @(
'DNSHostName',
@{name='lastLogon';e={[datetime]::FromFileTime($PSItem.'lastLogon') }},
@{name='lastLogontimestamp';e={[datetime]::FromFileTime($PSItem.'lastLogontimestamp') }},
'operatingSystem','operatingSystemVersion','whenCreated','whenChanged','DistinguishedName',
@{name='InUse';e={''}},
@{name='CurrentAccessList';e={''}},
@{name='Applications';e={''}},
$AdComputerFilter = 'DNSHostName','lastLogon','lastlogontimestamp','operatingSystem','operatingSystemVersion','whenChanged','whenCreated'
$SelectObjectFilter = @(
'DNSHostName',
@{name='lastLogon';e={[datetime]::FromFileTime($PSItem.'lastLogon') }},
@{name='lastLogontimestamp';e={[datetime]::FromFileTime($PSItem.'lastLogontimestamp') }},
'operatingSystem','operatingSystemVersion','whenCreated','whenChanged','DistinguishedName',
@{name='InUse';e={''}},
@{name='CurrentAccessList';e={''}},
@{name='Applications';e={''}},
$Computers = Get-ADComputer -filter * -SearchBase 'OU=Servers,OU=ComputersX,DC=contoso,DC=com' | Select-Object -ExpandProperty Name
$Allcerts = Invoke-Command -ComputerName $Computers -ScriptBlock {
Get-childItem Cert:\LocalMachine\My | Select-Object DnsNameList,NotBefore,NotAfter,Thumbprint,Issuer,Subject
} -ErrorAction SilentlyContinue
#region get the cert we're looking for
$thumbprint = 'PLACEYOURTHUMBPRINTHERE'
$Computers = Get-ADComputer -filter * -SearchBase 'OU=Servers,OU=ComputersX,DC=contoso,DC=com' | Select-Object -ExpandProperty Name
$Allcerts = Invoke-Command -ComputerName $Computers -ScriptBlock {
Get-childItem Cert:\LocalMachine\My | Select-Object DnsNameList,NotBefore,NotAfter,Thumbprint,Issuer,Subject
} -ErrorAction SilentlyContinue
#region get all certs that expired
#get current date
$date = Get-Date
$BitLockerVolumes = Get-BitLockerVolume
foreach ($blv in $BitLockerVolumes) {
Backup-BitLockerKeyProtector -MountPoint $blv.MountPoint -KeyProtectorId (($blv.KeyProtector)[1] | Select-Object -ExpandProperty KeyProtectorID)
}
ComputerName: NBMCZERNIAWSKI2
VolumeType Mount CapacityGB VolumeStatus Encryption KeyProtector AutoUnlock Protection
Point Percentage Enabled Status
$BitLockerVolumes = Get-BitLockerVolume
foreach ($blv in $BitLockerVolumes) {
BackupToAAD-BitLockerKeyProtector -MountPoint $blv.MountPoint -KeyProtectorId (($blv.KeyProtector)[1] | Select-Object -ExpandProperty KeyProtectorID)
}
ComputerName: NBMCZERNIAWSKI2
VolumeType Mount CapacityGB VolumeStatus Encryption KeyProtector AutoUnlock Protection
Point Percentage Enabled Status
$ComputerName = 'nbmczerniawski2'
$DNComputer = Get-ADComputer $computerName | Select-Object -ExpandProperty DistinguishedName
$obj = get-adobject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -SearchBase $DNComputer -Properties 'msFVE-RecoveryPassword' | Select-Object Name,msFVE-RecoveryPassword
[Ordered]@{
ComputerName = $ComputerName
RecoveryPassword = $obj.'msFVE-RecoveryPassword'
Date = Get-Date -Date ($obj.Name ).Split('{')[0]
KeyID = (($obj.Name ).Split('{')[1]).TrimEnd('}')
}