0

H ALL,

my problem that the get-user command doesn't show up output because get-wmiobject is executed before get-user command takes time to be executed ,so I used sleep command that makes the output of get-user show up .

but I need another way than sleep command , this is a part of my script

the whole code


#Run as administrator#

param([switch]$Elevated)

function Test-Admin {
    $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
    $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

if ((Test-Admin) -eq $false)  {
    if ($elevated) {
        # tried to elevate, did not work, aborting
    } else {
        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
    }
    exit
}

'running with full privileges'

#hardware#
Write-Host "----------------------------------------"
            Write-Host " #######Hardware info#########"
            Write-Host "----------------------------------------`r`n"
write-output ("CPU is $((Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors)");
cmd.exe /c WMIC CPU Get DeviceID,NumberOfCores,NumberOfLogicalProcessors
Write-Output ("Ram is $(Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum | Foreach {"{0:N2}" -f ([math]::round(($_.Sum / 1GB),2))})");
#Get-Disk | Format-Table -AutoSize PartitionStyle,@{Name="Size, Gb"; Expression={[int]($_.Size/1GB)}};
#Get-Partition | Format-list DriveLetter,IsActive,IsBoot,OperationalStatus,@{Name="Size, Gb"; Expression={[int]($_.Size/1GB)}};
$disks = Get-Disk
For ($i=0; $i -lt $disks.Length ; $i++)
 {
 Write-Output("Disk $($i) is selected now");
 $partition = @()
 $partition.Add((Get-Partition -DiskNumber $i | Select-Object DiskNumber,PartitionNumber,DriveLetter,IsActive,@{Name="Size, Gb"; Expression={[int]($_.Size/1GB)}},type))
  Write-Output("partitons in disk $($i)")
  Write-Host ($($partition) | Format-Table | Out-String)
 For ($j=1; $j -le $partition.Length ; $j++)
 {

 if( $partition[$j].DriveLetter -ne $null)
 {
 Write-Output("volume in disk $($i)")

 $volume = Get-Volume -DriveLetter $partition[$j].DriveLetter -ErrorAction SilentlyContinue | select DriveLetter,FriendlyName,FileSystemType,HealthStatus,OperationalStatus,@{Name="SizeRemaining, Gb"; Expression={[int]($_.SizeRemaining/1GB)}},@{Name="Size, Gb"; Expression={[int]($_.Size/1GB)}}
 Write-Host ($($volume) | Format-Table | Out-String)
 }

 }
}
   Get-WmiObject -Class Win32_LogicalDisk | Select Deviceid,volumename -Wait
        

#Get-WmiObject -Class Win32_LogicalDisk | Select Deviceid,volumename;

#Domain#
Write-Host "----------------------------------------"
            Write-Host ""############Domain and Domain Controller info#############""
            Write-Host "----------------------------------------`r`n"
Write-Output("Computer name is $(hostname)");
Write-Output("$(cmd /c echo %USERDOMAIN%)");
write-output("$($env:LOGONSERVER)");


#users#

Write-Host "----------------------------------------";
            Write-Host "############Users#############";
            Write-Host "----------------------------------------`r`n";

Write-Host ($(Get-LocalGroupMember -Group "Administrators") | Format-Table | Out-String)


  • What is `Get-User` command? Where did you use it? – SavindraSingh Jun 23 '23 at 15:24
  • Reads like the issue of implicit `Format-Table` being delayed. Fix it by piping `Get-WmiObject` command to `Format-Table` or `Format-List` to avoid implicit `Format-Table`. More info: https://stackoverflow.com/questions/70694197/what-causes-the-output-of-select-object-to-be-truncated/70699196#70699196 – zett42 Jun 23 '23 at 15:29
  • sorry I didn't copy the users part – user3737708 Jun 24 '23 at 09:06
  • I make edit to the question .now you can see where I put get-user in the script ,the problem arises when I don't use sleep 5 after "get-wmi " the output of get-user doesn't show up – user3737708 Jun 24 '23 at 09:10

0 Answers0