PowerShell Interview Basic Questions and Answers
How do you find the computer name? PS C:> hostname GOVARDHAN-PC PS C:> $env:COMPUTERNAME GOVARDHAN-PC PS C:> Get-WmiObject win32_operatingsystem | Select-Object -property PSComputerName, CSName PSComputerName CSName ————– —— GOVARDHAN-PC GOVARDHAN-PC PS C:> Get-ItemProperty -Path “HKLM:SYSTEMCurrentControlSetControlComputerNameActiveComputerName” -Name “ComputerName” | Select-Object -Property Computername ComputerName GOVARDHAN-PC PS C:> How do you find the free space of C: drive in GBs? PS C:> Get-PSDrive –Name C | ForEach-Object {[math]::round($.free/1GB)} 204 PS C:> Get-PSDrive –Name C | % {[math]::round($.free/1GB)} 204 PS C:> Get-PSDrive –Name C | Select-Object -Property free | % {[math]::round($_.free/1GB)} 204 PS C:> Get-WMIObject Win32_LogicalDisk -filter “DeviceID=’C:’” | % {[math]::round($_.FreeSpace/1GB)} 204 PS […]
Read more