I am trying to collect some computer and monitor information from systems that have PowerShell v2.
If I run the code below when logged in as local admin it runs fine however when I call it from a bat with RunAS it fails.
I’m using "." as the drive letter changes due to running from USB.
I can’t run this remotely either as PowerShell is disabled for remoting.
Can anyone tell me what is wrong?
I should have said that I am running this on Windows 7/10 machines.
Bat
powershell.exe "Start-Process powershell.exe -ArgumentList '-ExecutionPolicy Bypass -File .\Monitor-Info.ps1' -Verb RunAs"
PS
$Monitor = Get-WmiObject wmiMonitorID -namespace root\wmi $Computer = Get-WmiObject -Class Win32_ComputerSystem $outPath = '.\Audit.csv' $Monitor | %{ $psObject = New-Object PSObject $psObject | Add-Member NoteProperty ComputerName "" $psObject | Add-Member NoteProperty ComputerType "" $psObject | Add-Member NoteProperty ComputerSerial "" $psObject | Add-Member NoteProperty MonitorSerial "" $psObject | Add-Member NoteProperty MonitorType "" $psObject.ComputerName = $env:computername $psObject.ComputerType = $Computer.model $psObject.ComputerSerial = $Computer.Name $psObject.MonitorSerial = ($_.SerialNumberID -ne 0 | %{[char]$_}) -join "" $psObject.MonitorType = ($_.UserFriendlyName -ne 0 | %{[char]$_}) -join "" If ($psObject.MonitorSerial -ne 1){ $psObject | ConvertTo-Csv -NoTypeInformation | Out-File -Append $outPath } }