-1
我想獲取用戶輸入的目標計算機,我可以運行此腳本。如果沒有指定計算機名稱,我想顯示一條錯誤消息。恩。我選擇dc1和所有的BIOS信息,Os信息和硬盤顯示爲dc1而不是我的本地計算機。關於如何實現這一點的任何想法?Powershell,獲取計算機名稱的用戶輸入並顯示該計算機BIOS信息,操作系統信息和磁盤信息
#Clears the screen
cls
#Sets status to 0 just incase its not already zero, option 4 sets status to 4 and exit the loop
$status = 0
#Gets the BIOS information
$biosInfo = get-CIMInstance -Class CIM_BIOSElement |select-Object SMBIOSBIOSVersion, Manufacturer, SerialNumber, Version | Format-Table
#Gets the Operating System information
$osInfo = get-CIMInstance -Class CIM_OperatingSystem | Select-Object Caption, Version |Format-List
#Gets the Disk information
$discInfo= get-CIMInstance -Class CIM_LogicalDisk |Select-Object DeviceID, FreeSpace, Size |Format-List @{Name=‘DeviceID‘;Expression={$_.DeviceID}}, @{Name=‘FreeSpace(InPercent)’;Expression={[math]::Round($_.FreeSpace/$_.Size,2)*100}}, @{Name=‘Size(GB)’;Expression={[int]($_.Size/1GB)}}
#Function to select computer name
function name {
$a = get-cimInstance -Class CIM_ComputerSystem.computername
}
#Menu selection zone!
Write-Host "Query Computer System Main Menu"
Write-Host ""
Write-Host "1 Display Current BIOS information"
Write-Host "2 Display Operating System Information"
Write-host "3 Display Hard Disk Information"
Write-Host "4 Exit"
Write-Host ""
do
{
$status = read-host "Please enter and Option"
$computer = Read-Host "Enter target computer name"
if ($computer -ne $computer){Write-host "ERROR! Please enter a target computer name" }
if ($status -ne 4){
}
#Where the menu magic happens
switch ($status){
1{ $biosInfo ; pause}
2{ $osInfo ; pause}
3{ $discInfo ; pause}
4{ $status_text = '4 Exit' ;$status = 4}
default {"Please select a number in the list!"}
}
}
#Exits the do loop when status is equal to 4
while ($status -ne 4)
我想出了錯誤部分,但我仍然需要弄清楚如何選擇在我的域中的計算機。 –
你是什麼意思選擇一個在你的域名的計算機?如果檢查AD是否有效? – Matt
如果我輸入dc1,我想顯示dc1的統計數據,是的,我想檢查AD,看它是否有效。如果這使得現場。 –