I wanted to write a Powershell module that can read the information from all PCs in my domain. The script works as well at the moment, but I would like to make multiple selections possible for the "Switch" param. Example: "Get-BERPCinfoFilter - Disk -Serial -Processor". How do I have to adapt the "if" query for the "switch" parameters so that this is possible? Thanks in advance.
function Get-BERPCinfoFilter {
param(
[switch]$Processor,
[Switch]$Videocard,
[Switch]$Disk,
[Switch]$memory,
[Switch]$Serial
)
Write-Host Please wait...
#Search all PCs in Domain
$ADC = Get-ADComputer -SearchBase <#Ou from Domain#> | Select-Object -ExpandProperty Name
#Get informations from this PCs
$Function = ForEach ($Computer in $ADC){
$Computername = $Computer
$Connection = Test-Connection $Computername -Count 1 -Quiet
if($Connection -match "True"){
Write-Host "$Computername is reachable!" -ForegroundColor Green
#Processor
if($Processor -match "True"){
Get-CimInstance -ComputerName $Computername -Class Win32_Processor |
Select-Object -Property Name
}
#Videocard
if($Videocard -match "True"){
Get-CimInstance -ComputerName $Computername -Class Win32_VideoController |
Select-Object -Property Name,DriverVersion,@{Label="DriverDate";Expression={$_.DriverDate.ToString("dd.MM.yyyy")}}
}
#Disk
if($Disk -match "True"){
Get-CimInstance -ComputerName $Computername -Class Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID, VolumeName, @{n="Size in GB";e={[math]::truncate($_.size / 1GB)}}, @{n="FreeSpace in GB";e={[math]::truncate($_.freespace / 1GB)}}
}
#Memory
if($Memory -match "True"){
Get-CimInstance -ComputerName $Computername -class Win32_Physicalmemory |
Select-Object Devicelocator,@{n="Capacity in GB";e={[math]::truncate($_.capacity / 1GB)}}
}
#Serial
if($Serial -match "True"){
Get-CimInstance -ComputerName $Computername -class win32_bios |
Select-Object Serialnumber
}
}
if($Connection -match "False"){
Write-Host "$Computername is not reachable!" -ForegroundColor Red
}
}
$Pfad = "$env:USERPROFILE\Desktop\Result.csv"
$Function | Export-Csv -Path $Pfad -NoTypeInformation -Delimiter ";"
Write-Host "The result is saved at path: $Pfad" -ForegroundColor Yellow
}
Aucun commentaire:
Enregistrer un commentaire