Get linux disk details using windows powershell

windows disks powershell linux 5 years, 11 months ago
$computer = "172.16.15.7" $linuxcredentils = Get-Credential -Message "linux vm ""$computer"" credentials " $Linsession = New-SSHSession -ComputerName $computer -Credential $linuxcredentils $command1 = Invoke-SSHCommand -SessionId $Linsession.SessionId -Command "lsblk" $command2 = invoke-sshcommand -SessionId $Linsession.SessionId -Command "[ -d ¨/sys/firmware/efi¨ ]&&echo ¨EFI/UEFI¨||echo ¨NOT EFI¨" $jsonoutput =New-Object System.Collections.ArrayList $diskncompute1 =New-Object System.Collections.ArrayList for($i=1;$i -lt ($command1.Output.Length); $i++) { $diskn=@{} $temp = $command1.Output[$i].Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries) if($temp[5] -eq "disk"){ $partition = 0 for($j = ($i+1);$j -lt ($command1.Output.Length);$j++){ $temp1 = $command1.Output[$j].Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries) if ($temp1[5] -eq "disk"){ break } elseif($temp1[5] -eq "part"){ $diskn[$temp1[0]] = $temp1[3] $partition = $partition+1 } else{} } $diskdetails1 = @{} $diskdetails1.PhysicalDisk = $temp[0] $diskdetails1.DiskSize = $temp[3] $diskdetails1.partitionCount = $partition if($partition -eq 0){ $diskdetails1.ParititionSizes = $null $diskdetails1.Driveletters = $null } else{ $diskdetails1.ParititionSizes =$diskn.Values $diskdetails1.Driveletters = $diskn.Keys } #$out = @{} #$out.computerName = $computer #$out.diskDetails = $diskdetails1 $diskncompute1.Add($diskdetails1)| Out-Null } } $out =@{} $out.computerName = $computer $out.diskDetails = $diskncompute1 $out.EFIDetails = ($($command2.Output).ToString()) $jsonoutput.Add($out) | Out-Null $tempstring = $jsonoutput|ConvertTo-JSON -Depth 5
2002
Instructions

Prerequisite - posh-ssh module needs to be imported

Posted By
vi editor save without exit from editor
:wq # will save and exit
:w # will save
:q! # exit without saving
vi linux shell
kishore_kumar
Linux Navigation
pwd  #print the name of current working 
cd  #change directory
ls #List directory contents
linux shell
Ramya Ramya
Finding usage of the file system in linux usi
import subprocess
threshold = input("Enter the threshold v
child = subprocess.Popen(['df','-h'],std
python linux subprocess
Ramya Ramya
Find out if Front Page Server Extensions(FPSE
Import-Module WebAdministration
$owsadmPath = "%ProgramFiles%\Common Fil
    $hash = @{}
powershell azure fpse
abhi abhi
Login to Azure account - RM
$azureAccountName = "abc@xyz.com"
    $azurePassword = ConvertTo-SecureStr
    $psCred = New-Object System.Manageme
azure powershell
abhi abhi
PowerShell scirpt to delete old IIS log files
$LogPath = "c:\inetpub\logs\LogFiles\W3S
$maxDaystoKeep = -30 
$outputPath = "c:\cleanuptask\Cleanup_Ol
powershell iis log file deletion
abhi abhi
PowerShell script to install IIS server role
Try
{
    $GetWebServer = Get-WindowsFeature -
vm custom script extension powershell azure iis
abhi abhi
Testing website in IIS
$Url = $args[0]
$UseDefaultCredentials = $args[1]
$Proxy = $args[2]
powershell iis vm custom script extension azure
abhi abhi
Deep Security Agent installation
$baseUrl=$arg[0]


agent powershell
abhi abhi
To download the artifact from repo
$ErrorActionPreference = 'Stop'
$S3Name=$args[0]
$EnvName=$args[1]
powershell download_artifact
sandeep sandeep