Created
July 12, 2020 06:33
-
-
Save NicoNekoru/5a7060b55763c48c99d3da85582e6017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Global:Get-LocalInfo { | |
<# | |
.NAME | |
Get-LocalInfo | |
.SYNTAX | |
Get-LocalInfo [-NetworkInfo] [-OSInfo] [-DriveInfo] [<CommonParameters>] | |
.PARAMETERS | |
-DriveInfo | |
Required? false | |
Position? Named | |
Accept pipeline input? false | |
Parameter set name (All) | |
Aliases None | |
Dynamic? false | |
Required? false | |
Position? 0 | |
Accept pipeline input? false | |
Parameter set name (All) | |
Aliases None | |
Dynamic? false | |
-NetworkInfo | |
Required? false | |
Position? Named | |
Accept pipeline input? false | |
Parameter set name (All) | |
Aliases None | |
Dynamic? false | |
-OSInfo | |
Required? false | |
Position? Named | |
Accept pipeline input? false | |
Parameter set name (All) | |
Aliases None | |
Dynamic? false | |
<CommonParameters> | |
This cmdlet supports the common parameters: Verbose, Debug, | |
ErrorAction, ErrorVariable, WarningAction, WarningVariable, | |
OutBuffer, PipelineVariable, and OutVariable. For more information, see | |
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). | |
.INPUTS | |
None | |
.OUTPUTS | |
System.Object | |
.ALIASES | |
None | |
.SYNOPSIS | |
Gets information about the state of the local computer | |
--------- Example 1: Get information about drives as a table --------- | |
PS C:\> Get-LocalInfo -DriveInfo | Format-Table | |
Name Used Free Root TotalStorage | |
---- ---- ---- ---- ------------ | |
A 0.390018463134766 931.106071472168 A:\ 931.496089935303 | |
C 80.2846870422363 384.867710113525 C:\ 465.152397155762 | |
This command gets the name, root, and storage information about the drives connected to the computer | |
--------- Example 2: Get information about the network --------- | |
PS C:\> Get-LocalInfo -NetworkInfo | Format-Table | |
HostName NetworkName NetworkDevice PublicIP IPV4Address IPV6Address DefaultGateway | |
-------- ----------- ------------- -------- ----------- ----------- -------------- | |
DESKTOP-123456 MyNetwork Intel(R) Wi-Fi 6 193.177.20.7 192.168.1.20 fe80::1952:5dc1:c96a:8ffc%8 192.168.1.1 | |
This command gets the computer name of the host, network connected to, network adapter, and other details. | |
--------- Example 3: Get information about your operating system --------- | |
PS C:\> Get-LocalInfo -OSInfo | Format-Table | |
LiscensedTo OSName OSArchitecture SystemDirectory WindowsVersion BuildNumber | |
----------- ------ -------------- --------------- -------------- ----------- | |
example@example.com Microsoft Windows 10 Home 64-bit C:\Windows\system32 2004 19041 | |
This comamnd will get information about the OS like the version, build number, name, and others | |
--------- Example 3: Gets everything --------- | |
PS C:\Users\kaima> Get-LocalInfo | |
Name : A | |
Used : 0.390018463134766 | |
Free : 931.106071472168 | |
Root : A:\ | |
TotalStorage : 931.496089935303 | |
Name : C | |
Used : 80.286205291748 | |
Free : 384.866191864014 | |
Root : C:\ | |
TotalStorage : 465.152397155762 | |
HostName : DESKTOP-123456 | |
NetworkName : MyNetwork | |
NetworkDevice : Intel(R) Wi-Fi 6 | |
PublicIP : 193.177.20.7 | |
IPV4Address : 192.168.1.20 | |
IPV6Address : fe80::1952:5dc1:c96a:8ffc%8 | |
DefaultGateway : 192.168.1.1 | |
LiscensedTo : example@example.com | |
OSName : Microsoft Windows 10 Home | |
OSArchitecture : 64-bit | |
SystemDirectory : C:\Windows\system32 | |
WindowsVersion : 2004 | |
BuildNumber : 19041 | |
.REMARKS | |
None | |
#> | |
#Requires -PSEdition Desktop -Version 3.0 | |
[CmdletBinding()] | |
param( | |
[switch]$NetworkInfo, | |
[Parameter(Mandatory=$false)] | |
[switch]$OSInfo, | |
[Parameter(Mandatory=$false)] | |
[switch]$DriveInfo, | |
[Parameter(Mandatory=$false)] | |
[ValidateSet("List","Table")] | |
[string]$Format = "List" | |
) | |
if ($format -ne "List" -and $format -ne "Table") | |
{ | |
$errorId = "FormatTypeNotSupported" | |
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument | |
$errorMessage = "Format '$format' is not supported for this function" | |
$exception = [System.InvalidOperationException]::New($errorMessage) | |
$errorRecord = [System.Management.Automation.ErrorRecord]::New($exception, $errorId, $errorCategory, $null) | |
$PSCmdlet.ThrowTerminatingError($errorRecord) | |
} | |
if (!($NetworkInfo -eq $osinfo -eq $driveinfo)) | |
{ | |
$NetworkInfo = $osinfo = $driveinfo = $true | |
} | |
if ($driveinfo) | |
{ | |
$GPSD = Get-PSDrive | Where-Object {$_.Provider.Name -eq "FileSystem"} | |
$DRI = @() | |
$GPSD | | |
ForEach-Object {$DRI += [PSCustomObject]@{ | |
Name = ($_.Name) | |
Used = ($_.Used/1GB) | |
Free = ($_.Free/1GB) | |
Root = ($_.Root) | |
TotalStorage=($_| ForEach-Object {($_.Used + $_.Free)/1GB}) | |
} | |
} | |
$DRI | |
} | |
if ($NetworkInfo) | |
{ | |
$GNIPC = (Get-NetIPConfiguration -InterfaceAlias "Wi-Fi") | |
$NTI = @() | |
$NTI +=[PSCustomObject]@{ | |
HostName=$env:computername | |
NetworkName=$GNIPC.NetProfile.Name | |
NetworkDevice=$GNIPC.InterfaceDescription | |
PublicIPV4=(Invoke-WebRequest ifconfig.me/ip).Content.Trim() | |
PublicIPV6=((iwr ip6.me/api).Content.trimstart("IPv6,") -split ',')[0] | |
IPV4Address=$GNIPC.IPv4Address.IPAddress | |
IPV6Address=$GNIPC.IPv6Address.IPAddress | |
DefaultGateway=$GNIPC.IPv4DefaultGateway.NextHop | |
} | |
$NTI | |
} | |
if ($OSInfo) | |
{ | |
$OSI = @() | |
$OSI += [PSCustomObject]@{ | |
LiscensedTo = (Get-WmiObject Win32_OperatingSystem).RegisteredUser | |
OSName = (Get-WmiObject Win32_OperatingSystem).Caption | |
OSArchitecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture | |
SystemDirectory = (Get-WmiObject Win32_OperatingSystem).SystemDirectory | |
WindowsVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId | |
BuildNumber = (Get-WmiObject Win32_OperatingSystem).BuildNumber | |
} | |
$OSI | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment