27 February 2021

Usefull command's and little PowerShell scripts

Quickly get the Computer Name, Model, Make, and other useful information


Get-WMIObject -Class Win32_ComputerSystem             
information about the System            
            
Get-WMIObject -Class Win32_BIOS             
Information about the BIOS            
            
Get-WMIObject -Class Win32_Baseboard             
Information about the Motherboard            
            
Get-WMIObject -Class Win32_Processor             
Information about the CPU            
            
Get-WMIObject -Class Win32_LogicalDisk             
Information about Logical Drives (Includes mapped drives and I believe PSDrives)            
            
Get-WMIObject -Class Win32_DiskDrive             
Information about Physical Drives            
            
Get-WMIObject -Class Win32_PhysicalMemory             
Information about the Memory            
            
Get-WMIObject -Class Win32_NetworkAdapter             
Information about the NIC            
            
Get-WMIObject -Class Win32_NetworkAdapterConfiguration             
Information about the NICs Configuration


Check your PowerShell Version

$PSVersionTable



Restart all Network Adapters *Must be run as admin or at least local admin*

Requires PowerShell 3.0+

Get-NetAdapter | Restart-NetAdapter


Browse UNC path with PowerShell

To access UNC via PowerShell;

cd \\servername\C$\Path\To\File



Copy a file to all users Desktop’s

$Users = Get-ChildItem C:\Users\ -Exclude “Administrator”,”Public”,”Default*” # Exclude any other defaults that you don’t want.            
            
foreach($User in $Users.name){             
$Path = “C:\Users\$User\Desktop”;             
Copy-Item -Path “\\Path\To\Source\File.txt” -Destination $Path\File.txt             
}


Get free disk space on drives

This can either be run locally or part of a larger script to hit multiple machines.

$Drive=Get-WmiObject Win32_LogicalDisk -Filter “DriveType = 3”             
$DriveSize=$Drive.Size;$DriveSize=[math]::Round($DriveSize/1GB)             
$FreeSpace=$Drive.FreeSpace;$FreeSpace=[math]::Round($FreeSpace/1GB)             
$DriveName=$Drive.Name             
$ComputerName=Get-WmiObject Win32_ComputerSystem;$ComputerName=$ComputerName.Name             
$UsedSpace=$DriveSize  $FreeSpace;$UsedSpace=[string]$UsedSpace+” GB free on drive $DriveName on computer $ComputerName”            
            

26 February 2021

Enable Wake On Lan with PowerShell and send Wake On Lan packet with PowerShell

Credit for the script goes to Jan-Henrik Damaschke at https://www.itinsights.org

function Set-WakeEnabled

{            
<#
.SYNOPSIS

Set WoL on nic

Author: Jan-Henrik Damaschke (@jandamaschke)
License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None

.DESCRIPTION

Set Wake on Lan (WOL) settings for specific network interface card

.PARAMETER InterfaceName

Specifies the name of the interface where WoL setting should be changed

.PARAMETER WakeEnabled

Specifies if WoL should be enabled or disabled

.EXAMPLE

PS C:\> Set-WakeEnabled -InterfaceName Ethernet -WakeEnabled $true

.LINK

http://itinsights.org/
#>            
            
[CmdletBinding()] Param(            
        [Parameter(Mandatory = $True, ParameterSetName="InterfaceName")]            
        [String]            
        $InterfaceName,            
            
        [Parameter(Mandatory = $True)]            
        [String]            
        $WakeEnabled,            
            
        [Parameter(Mandatory = $True, ParameterSetName="ConnectionID")]            
        [String]            
        $NetConnectionID            
)            
            
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {            
        Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"            
        Break            
    }            
            
    $nicsWakeEnabled = Get-CimInstance -ClassName MSPower_DeviceWakeEnable -Namespace root/wmi            
    $nics = Get-CimInstance -ClassName Win32_NetworkAdapter | Where-Object NetEnabled -eq $true            
            
    if ($InterfaceName){            
        $nic = $nics | Where-Object Name -eq $InterfaceName            
    }            
    else {            
        $nic = $nics | Where-Object NetConnectionID -eq $NetConnectionID            
    }            
            
    $nicWakeEnabled = $nicsWakeEnabled | Where-Object InstanceName -like "*$($nic.PNPDeviceID)*"            
                
    $enabled = $nicWakeEnabled.Enable            
            
    if (!($enabled -and $WakeEnabled)){            
        Set-CimInstance $nicWakeEnabled -Property @{Enable=$enabled}            
    }            
}

Find the mac address of the nic you want to wake up.
Get-WmiObject win32_networkadapterconfiguration | select description, macaddress
Or
Get-CimInstance win32_networkadapterconfiguration | select description, macaddress

To send a wake on lan package:
Install-Module -Name wakeonlan -Force
Import-module -Name wakeonlan
Invoke-WakeOnLan -MacAddress 84:D2:4A:0F:78:44

16 February 2021

Open Windows Explorer collapsed

 Anoying.

When opening Windows Explorer it opens with all folders collapsed. The behaviour can come from different settings, such as:

Showing all folders
Allowing network discovery
Last opened folder saved when closing the explorer

And probably a few I don't k now about.

Some dude (EpilepticUnderscore) over at social.technet.com created a batch file to overcome this annoyance.
See the original thread here: Collapse all folder-trees when closing Explorer (microsoft.com)

The batch job way: