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”            
            

No comments:

Post a Comment