내가 다음 줄을 호출 명령 내에서 파워 쉘 결과의 일부를 제거 ForEach 문을 잘 작동하지만 출력 그냥 : OS30 : OEM_SLP는
나는 그것을 분해 할 수 있지만 다음 마지막 컴퓨터에서 값을 걸리고 모든 항목에 대해 넣습니다 :
$OSType = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance SoftwareLicensingProduct | Where-Object -FilterScript { ($_.Description -like "W*" -and $_.licensestatus -eq 1) } | select-object -first 1 -ExpandProperty Description} `
$OS1 = $OSType.Split(',')[1]
$OS2 = $OS1.Split(' ')[1]
"OSType" = $OS2
아래 3 줄에 Invoke 명령을 사용하려고하면 오류가 발생합니다. 어떤 아이디어?
$OSType = (Invoke-Command -ComputerName $Computer -ScriptBlock {
Get-CimInstance SoftwareLicensingProduct |
Where-Object -FilterScript { ($_.Description -like "W*" -and $_.licensestatus -eq 1) } |
select-object -first 1 -ExpandProperty Description
}) -replace '.*,\s?(\S+).*', '$1'
그러나, 나는 개체를 만들기 전에 번 Get-WmiObject –class Win32_processor
만 를 호출 할 것을 권장 높은 것 :
$computers = Get-Content -Path "C:\Computers.txt"
$Results = @()
ForEach ($Computer in $Computers) {
$Results += New-Object PSObject -Property @{
"Computer" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | select-object -first 1 -ExpandProperty SystemName } `
"CPU1" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*1*") -or ($_.SocketDesignation -like "*0*") } | select-object -first 1 -ExpandProperty Name } `
"Cores1" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*1*") -or ($_.SocketDesignation -like "*0*") } | select-object -first 1 -ExpandProperty NumberOfCores } `
"LogProc1" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*1*") -or ($_.SocketDesignation -like "*0*") } | select-object -first 1 -ExpandProperty NumberOfLogicalProcessors }
"CPU2" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*2*") -or ($_.SocketDesignation -like "*#1*") } | select-object -first 1 -ExpandProperty Name } `
"Cores2" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*2*") -or ($_.SocketDesignation -like "*#1*") } | select-object -first 1 -ExpandProperty NumberOfCores } `
"LogProc2" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject –class Win32_processor | Where-Object -FilterScript { ($_.SocketDesignation -like "*2*") -or ($_.SocketDesignation -like "*#1*") } | select-object -first 1 -ExpandProperty NumberOfLogicalProcessors } `
"OS" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance Win32_OperatingSystem | Select-Object -ExpandProperty Caption } `
#"OSType" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance SoftwareLicensingProduct | Where-Object -FilterScript { ($_.Description -like "W*" -and $_.licensestatus -eq 1) } | select-object -first 1 -ExpandProperty Description} `
$OSType = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance SoftwareLicensingProduct | Where-Object -FilterScript { ($_.Description -like "W*" -and $_.licensestatus -eq 1) } | select-object -first 1 -ExpandProperty Description} `
$OS1 = $OSType.Split(',')[1]
$OS2 = $OS1.Split(' ')[1]
"OSType" = $OS2
"SP" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance Win32_OperatingSystem | Select-Object -ExpandProperty ServicePackMajorVersion } `
"OSArch" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance Win32_OperatingSystem | Select-Object -ExpandProperty OSArchitecture } `
"Office" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object -FilterScript { (($_.Publisher -like "Microsoft*") -and ($_.DisplayName -like "*Office 64*")) } | Select-Object -first 1 -ExpandProperty DisplayName }
"FullSQL" = Invoke-Command -ComputerName $Computer -ScriptBlock {If (Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names") { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object -FilterScript { (($_.Publisher -like "Microsoft*") -and ($_.DisplayName -like "Microsoft SQL Server*(*-bit)")) } | Select-Object -first 1 -ExpandProperty DisplayName }}
}
}
$Results | Select-Object Computer, CPU1, Cores1, LogProc1, CPU2, Cores2, LogProc2, OS, OSType, SP, OSArch, Office, FullSQL | Sort-Object Computer
을 [ -2]'를 사용하십시오. $ OS1 = $ OSType.Split (',') [1] $ OS2 = $ OS1.Split ('') [1] "OSType"= $ OS2' – 4c74356b41