Comparación de variables en Windows PowerShell y PowerShell 7
Las variables automáticas de PowerShell se almacenan y mantienen mediante PowerShell. Esto se aplica a Windows PowerShell que se incluye con todos los sistemas operativos Windows, así como a PowerShell descargado a través de GitHub.
En esta publicación de blog, mostraré cómo comparar variables automáticas en Windows PowerShell y PowerShell 7.
Por ejemplo, falta la variable $IsWindows en Windows PowerShell. Tampoco tendría sentido comprobar si Windows está instalado o no, porque Windows PowerShell sólo se ejecuta en el sistema operativo Windows.
$IsWindows
Pero hay más diferencias que descubriremos ahora.
Guardar Varialbes en un archivo
Primero guardamos la lista de variables de Windows PowerShell en un archivo.
Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\windowspowershellvariables.txt
Luego guardamos las variables de PowerShell en un archivo.
Get-Variable | Select-Object -ExpandProperty Name | Out-File C:\Temp\powershellvariables.txt
Comparación de variables de Windows PowerShell y PowerShell
Aquí está la lista que nos muestra las diferencias:
Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt)
Para ver qué falta en Windows PowerShell en comparación con PowerShell, ejecute
(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "=>"} |
Select-Object -ExpandProperty InputObject) -join ", "
Para ver qué falta en PowerShell en comparación con Windows PowerShell, ejecute
(Compare-Object -ReferenceObject (Get-Content C:\Temp\windowspowershellvariables.txt) `
-DifferenceObject (Get-Content C:\Temp\powershellvariables.txt) |
Where-Object {$_.SideIndicator -eq "<="} |
Select-Object -ExpandProperty InputObject) -join ", "
Bueno, tarea cumplida. Espero que haya sido informativo, especialmente para aquellos lectores que suelen trabajar con variables automáticas.
¡Hasta la próxima con PowerShell!





