Skip to content

Instantly share code, notes, and snippets.

View dpo007's full-sized avatar

Dev dpo007

  • Ontario, Canada
View GitHub Profile
@dpo007
dpo007 / DiscoWrite.ps1
Last active August 27, 2020 17:40
PowerShell function :: A simple console Write-Host animation
function DiscoWrite {
param (
[string]$str,
[int]$speed = 25,
[switch]$NoNewline
)
$anim = @('.', '-', '+', '*', '#')
[int]$CursorTop = [Console]::CursorTop
@dpo007
dpo007 / Set-LenovoVirtualization.ps1
Last active July 10, 2020 13:01
PowerShell :: Enables or disables Intel virtualization settings in various Lenovo BIOSs
param (
[string]$BiosPass = 'YerPassword',
[switch]$Disable
)
$vendor = (Get-WMIObject -Class Win32_ComputerSystemProduct).Vendor
if ($vendor.ToUpper() -ne 'LENOVO') {
Write-Host ('This is intended for use with Lenovo devices only. "Vendor" returned "{0}", exiting.' -f $vendor)
Exit 666
}
@dpo007
dpo007 / GetHostNameFromUNC.ps1
Created April 13, 2020 19:31
PowerShell Function :: Get HostName From UNC Path
function GetHostNameFromUNC {
param (
[Parameter(Mandatory=$true)]
[string]$UNCPath
)
$UNCPath -match '\\\\(.*?)\\' | Out-Null
if ($Matches.Count -ge 2) {
return $Matches[1]
} else {
@dpo007
dpo007 / GetUnlinkedGPOs.ps1
Created February 3, 2020 16:05
PowerShell function :: Retrieve list of Group Policy Objects that are not linked to any OU.
function Get-UnlinkedGPOs {
[string[]]$results = @()
Get-GPO -All | ForEach-Object {
if ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" ) {
$results += $_.DisplayName
}
}
return $results
}
@dpo007
dpo007 / SetShareAcrossDevicesSettings.ps1
Last active January 16, 2020 17:56
PowerShell script :: Set "Share Across Devices" settings in Windows 10
##########################
# Sets "Share Across Devices" settings in Windows 10 to On/My devices only.
# - DPO, Jan. 2020
##########################
$path1 = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CDP'
$path2 = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CDP\SettingsPage'
$regKeys = @{
CdpSessionUserAuthzPolicy = '1'
@dpo007
dpo007 / ScanAllDrivesOnDisk.ps1
Last active January 14, 2020 20:37
PowerShell script :: Scan all drives with letters on given disk.
param (
[int]$DiskNumber = 0
)
Write-Host "Gathering SMART info for Disk $DiskNumber..."
$disk = Get-Disk $DiskNumber
$disk | Get-StorageReliabilityCounter | Select * | FL
$partitionsWithDriveLetters = $disk | Get-Partition | Where-Object { [bool]$_.DriveLetter }
@dpo007
dpo007 / CharIsEmpty.ps1
Last active January 14, 2020 18:40
Powershell function :: Tests to see if Char value is "empty".
# Tests to see if Char value is "empty".
# Ran into a need to test for "empty" [Char] DriveLetters when using Get-Partition,
# and the usual PS comparison techniques weren't working with Char (ie: Char is never Null).
# If you (re)cast it to a Boolean, it'll return expected $True\$False to test for "Empty".
# This Gist exists as a reminder of that.
function CharIsEmpty {
param (
[Parameter(Mandatory=$True)]
[char]$CharToTest
@dpo007
dpo007 / ComputerRenamer.ps1
Last active January 14, 2020 20:38
PowerShell script :: Wraps Rename-Computer, for use during scheduled/remote launches on Domain-Attached machines.
#################
# Wrapper for Rename-Computer
# - Intended to be used with an RMM/automated script launcher.
# - DPO, Jan. 2020
#################
param (
[Parameter(Mandatory=$True)]
[string]$NewName,
[Parameter(Mandatory=$True)]
[string]$DomainCreds,
@dpo007
dpo007 / RemoveProfile.ps1
Last active January 6, 2020 18:02
PowerShell function :: Delete matching user profile(s) from a Windows machine
# Warning: This cleans all profiles STARTING WITH THE USERNAME GIVEN. So "jsmith" would remove "jsmith", "jsmith.domain1.local", "jsmithly" etc.
function KillUserProfile {
Param (
[Parameter(Mandatory=$True)]
[string]$UserName
)
$profiles = Get-CimInstance win32_userprofile
@dpo007
dpo007 / ComputerIsInGroup.ps1
Last active January 14, 2020 18:42
PowerShell function :: Check if domain-joined computer is a member of AD group, without AD module.
function ComputerIsInGroup {
param (
[Parameter(Mandatory=$True)]
[string]$GroupName
)
# Get computer's DN
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher.Filter = "(&(objectCategory=Computer)(SamAccountname=$($env:COMPUTERNAME)`$))"