PowerShell Scripting For MOCK
Advance Scripting for PowerShell MOCK
Remote Query Hardware Information
// Query
Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName "RemoteComputerName or IP_PC"
Specify Parameters piping to Select-Object to identify more objects
Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName "RemoteComputerName or IP_PC" | Select-Object DeviceID, DriveType, Size, FreeSpace
Script to Automate the Remote Query and accepts a Computer name and prompts for a PC name if one is not provided
function Get_info {
param(
[parameter(Mandatory, Position=0)]
[string[]]$getPC=(Read-Host "Enter PC name: ")
)
if (-not $getPC) {
Write-Host "Please provide a PC or IP address to search."
} else {
# Proceed with your search logic here
foreach ($computerName in $getPC) {
Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName $computerName
}
}
}
# Call the function with one or more PC or IP addresses as arguments
Get_info -getPC LON-DC1
This script will accept a switch parameter to indicate whether alternate credentials are required.
Logging Function
Creating an Error Handler on the Script
Last updated