Obtener estatus de activacion de windows desde Powershell (PowerShell Get windows activation status)

Deja un comentario

En este post dejare el codigo en PowerShell para obtener el estatus de la activacion de Windows.


    $wpa = Get-WmiObject -class SoftwareLicensingProduct | Where-Object {$_.LicenseStatus -eq "1"}
    $InfoResult = @();
    $obj = New-Object –TypeName PSObject

    Write-Host $wpa

    if ($wpa)
    {
        foreach($item in $wpa) 
        {
         $itemDetails =
         @{            
                Date         = $(Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff")           
                Node         =    $(Get-Content env:computername) 
                Status       = ActivationStatus($item.LicenseStatus);
          }    

            $InfoResult += New-Object PSObject -Property $itemDetails ;           
        }
    } 
    else 
    {
        $status = "Unlicensed"

        $itemDetails =
         @{            
                Date         = $(Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff")           
                Node         =   $(Get-Content env:computername) 
                Status       =  $status;
          }    

            $InfoResult += New-Object PSObject -Property $itemDetails ;            
    }

   
   foreach($item in $InfoResult)
   {
            Write-Host " ";
            Write-Host "Fecha       : " $item.Date;
            Write-Host "Nodo        : " $item.Node;
            Write-Host "Estatus     : " $item.Status;
            Write-Host " ";
   }

La salida sera la siguiente:

Fecha : 2017-08-21 15:55:58.541
Nodo : MiPC
Estatus : Licensed

Si le sirvió no olviden comentar.

Saludos.

Obtener espacio disponible en el disco duro Powershell (Get Free Space in HardDisk PowerShell)

Deja un comentario

En este post dejare el codigo en PowerShell para obtener el espacio disponible del disco duro por particion.


$partitions= Get-WmiObject -Class Win32_LogicalDisk -Filter 'DriveType = 3' |Select-Object PSComputerName, Caption,@{N='Capacity_GB'; E={[math]::Round(($_.Size / 1GB), 2)}},@{N='FreeSpace_GB'; E={[math]::Round(($_.FreeSpace / 1GB), 2)}},@{N='PercentUsed'; E={[math]::Round(((($_.Size - $_.FreeSpace) / $_.Size) * 100), 2) }},@{N='PercentFree'; E={[math]::Round((($_.FreeSpace / $_.Size) * 100), 2) }}

foreach($z in $partitions)
{  
    Write-Host "Particion         : $($z.Caption)" ;    
    Write-Host "Capacidad Total   : $($z.Capacity_GB)  GB" ;    
    Write-Host "Espacio Libre     : $($z.FreeSpace_GB) GB" ;    
    Write-Host "Porcentaje Usado  : $($z.PercentUsed)  %" ;    
    Write-Host "Porcentaje Libre  : $($z.PercentFree)  %" ;   
    Write-Host "";   
}


La salida es la siguiente:

Particion : C:
Capacidad Total : 368.1 GB
Espacio Libre : 123.73 GB
Porcentaje Usado : 66.39 %
Porcentaje Libre : 33.61 %

Particion : E:
Capacidad Total : 97.14 GB
Espacio Libre : 19.71 GB
Porcentaje Usado : 79.71 %
Porcentaje Libre : 20.29 %

Si le sirvió no olviden comentar.

Saludos.

Obtener Software Instalado Powershell (Get software installed Powershell)

Deja un comentario

En este post dejare el codigo en PowerShell para obtener la lista de software instalado la pc donde se ejecute.


 $computer = $env:COMPUTERNAME;
	
		$LMkeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall","SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
		$LMtype = [Microsoft.Win32.RegistryHive]::LocalMachine
		$CUkeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
		$CUtype = [Microsoft.Win32.RegistryHive]::CurrentUser	
		
			$MasterKeys = @()
			$CURegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($CUtype,$computer)
			$LMRegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($LMtype,$computer)
			ForEach($Key in $LMkeys)
			{
				$RegKey = $LMRegKey.OpenSubkey($key)
				If($RegKey -ne $null)
				{
					ForEach($subName in $RegKey.getsubkeynames())
					{
						foreach($sub in $RegKey.opensubkey($subName))
						{
							$MasterKeys += (New-Object PSObject -Property @{
							"ComputerName" = $Computer
							"Name" = $sub.getvalue("displayname")
							"SystemComponent" = $sub.getvalue("systemcomponent")
							"ParentKeyName" = $sub.getvalue("parentkeyname")
							"Version" = $sub.getvalue("DisplayVersion")
							"UninstallCommand" = $sub.getvalue("UninstallString")
							})
						}
					}
				}
			}
			ForEach($Key in $CUKeys)
			{
				$RegKey = $CURegKey.OpenSubkey($Key)
				If($RegKey -ne $null)
				{
					ForEach($subName in $RegKey.getsubkeynames())
					{
						foreach($sub in $RegKey.opensubkey($subName))
						{
							$MasterKeys += (New-Object PSObject -Property @{
							"ComputerName" = $Computer
							"Name" = $sub.getvalue("displayname")
							"SystemComponent" = $sub.getvalue("systemcomponent")
							"ParentKeyName" = $sub.getvalue("parentkeyname")
							"Version" = $sub.getvalue("DisplayVersion")
							"UninstallCommand" = $sub.getvalue("UninstallString")
							})
						}
					}
				}
			}
			$MasterKeys = ($MasterKeys | Where-Object {$_.Name -ne $Null -AND $_.SystemComponent -ne "1" -AND $_.ParentKeyName -eq $Null} 
| Select-Object Name,Version,ComputerName,UninstallCommand | Sort-Object Name)
        
            $MasterKeys

#    si la linea de abajo se descomenta exporta el resultado anterior a un archivo CSV
#    $MasterKeys | Export-Csv 'Ruta_DelArchivo.csv';

Si le sirvió no olviden comentar.

Saludos.