Trying to get/print the current version of Aks cluster and checking which Kubernetes upgrade releases are available in the region where my AKS cluster resides and upgrading my AKS cluster. Below is my script where unable to upgrade from 1.23.12 to 1.24.3,hence its going to downgrading version(1.23.8). Hope you can assist me with a problem trying to execute a script block. Thanks in Advance
Param
(
[Parameter(Mandatory=$true)]
[String]
$AKSName,
[Parameter(Mandatory=$true)]
[String]
$SubscriptionID
)
Connect-AzAccount -Identity > $null
Set-AzContext -SubscriptionId $SubscriptionID > $null
$AKsResourceGroup= Get-AzResource -Name $AKSName | foreach {$_.ResourceGroupName}
$AKsLocation= Get-AzResource -Name $AKSName | foreach {$_.Location}
#Check Current Version Of Cluster
$CurrentVersion = Get-AzAksCluster -ResourceGroupName $AKsResourceGroup -Name $AKSName | select -ExpandProperty KubernetesVersion -WarningAction Ignore #> $null
"The CurrentVersion is $CurrentVersion" | ConvertTo-Json
#Check the availability versions to upgrade
$Versions = Get-AzAksVersion -Location $AKsLocation | where-Object {($_.OrchestratorVersion -gt $CurrentVersion) -and ($_.IsPreview -ne 'True')} | foreach {$_.OrchestratorVersion} -WarningAction Ignore
"These are the available versions $Versions" | ConvertTo-Json
$attempt3 =$versions.Replace(' ', ' , ')
$attempt3=$attempt3.replace(' " ' , " ")
$attempt3=$attempt3.replace(" ' "," ")
#for upgrading the latest version
$finalversion=$attempt3.Split(",")[0]
#AKS Upgrade
Set-AzAksCluster -ResourceGroupName $AKsResourceGroup -Name $AKSName -KubernetesVersion $finalversion -WarningAction Ignore > $null
#To check the status of AKS
Get-AzAksCluster -ResourceGroupName $AKsResourceGroup -Name $AKSName | Format-Table -Property Name, Location, KubernetesVersion, ProvisioningState
``
output:
"The CurrentVersion is 1.23.12"
"These are the available versions 1.23.8 1.24.3 1.24.6"
**Downgrading Kubernetes version 1.23.12 to 1.23.8 is not allowed. Available upgrades: 1.24.3,1.24.6.**
I tried to upgrade the AKS cluster version in my environment and got the below results
I have followed the below steps to upgrade the AKS cluster version
$RG-name= Get-AzResource -Name $AKSName | foreach {$_.ResourceGroupName}
$AKsLocation= Get-AzResource -Name $AKSName | foreach {$_.Location}
$CurrentVersion = Get-AzAksCluster -ResourceGroupName $RG-name -Name $AKSName | select -ExpandProperty KubernetesVersion -WarningAction Ignore #> $null
"The CurrentVersion is $CurrentVersion" | ConvertTo-Json
To check what are versions available in the cluster
$Version = Get-AzAksVersion -Location $AKsLocation | where-Object {($_.OrchestratorVersion -gt $CurrentVersion) -and ($_.IsPreview -ne 'True')} | foreach {$_.OrchestratorVersion} -WarningAction Ignore
"These are the available versions $Versions" | ConvertTo-Json
To Upgrade the version I have followed the below commands
$final =$version.Replace(' ', ' , ')
$final=$final.replace(' " ' , " ")
$final=$final.replace(" ' "," ")
#for upgrading the latest version
$finalversion=final.Split(",")[1]
#AKS Upgrade
Set-AzAksCluster -ResourceGroupName $RG-name -Name $AKSName -KubernetesVersion $finalversion -WarningAction Ignore > $null
When I check the below command I am able to see the updated version
Get-AzAksCluster -ResourceGroupName $RG-name -Name $AKSName | Format-Table -Property Name, Location, KubernetesVersion, ProvisioningState
Note:
We will get the upgraded version based on the available versions, I have used the split function split[1] because I need the next version of my current version if we need 1.24.6 version we have to use split[2] array function.
Related
Hope you can help me with a problem trying to execute a script block
Get-AzAksVersion -Location CanadaCentral | Where-Object -Property OrchestratorVersion -gt 1.22.11, IsPreview -ne $true
trying to get the versions greater than the current version and excluding the preview version, getting error as Parameter set cannot be resolved. Thanks in advance.
I tried to reproduce the same in my environment and got the same error as below:
Get-AzAksVersion -Location CanadaCentral | Where-Object -Property OrchestratorVersion -gt 1.22.11, IsPreview -ne $true
To resolve the error, try the below command:
Get-AzAksVersion -Location CanadaCentral | where-Object {($_.OrchestratorVersion -gt '1.22.15') -and ($_.IsPreview -ne 'True')}
I received a request to run this on each of my systems which pulls a list of installed applications and outputs it into a text file. I then have to combine all of these things into something more readable which will take a while. I am learning Powershell and want to make this be executed from one system, pull from a list of servers in a text file and run this query from one place against all of the systems:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > "$Env:userprofile\desktop\Installed Programs for $env:computername.txt"
I've started working on it but am thinking I am missing something to get this to work. I am currently piping this to a string to then output to a csv (I am open to suggestions). This is what I have so far.
# Computer running this script
$WhoAmI = $env:ComputerName
$ServerList = get-content -path "C:\scripts\ServerList.txt"
$Path = "C:\scripts\results"
foreach ($server in $ServerList)
{
$InstalledApps = Invoke-Command -ComputerName $server {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* }
$Results += $InstalledApps |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Out-String
}
Write-Host $InstallApps
# $InstallApps | export-csv "$Path\InstalledFiles.csv"
I currently am testing the functionality of the loop by just trying to get it to write to the screen. I only get a blank response.
You weren't getting output because you used the (undefined) variable $InstallApps instead of the variable $results.
With that said, I wouldn't recommend doing string concatenation in a loop. Something like this would be a more elegant approach:
Get-Content -Path 'C:\scripts\ServerList.txt' | ForEach-Object {
$server = $_
Invoke-Command -ComputerName $server -ScriptBlock {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
} | Select-Object #{n='Server';e={$server}}, DisplayName, DisplayVersion,
Publisher, InstallDate
} | Export-Csv 'C:\scripts\results\InstalledPrograms.csv' -NoType
I kind of figured it out. Rested eyes on a fresh day. Some mistakes in what I am writing out, etc. I am open to improvements if anyone has anything to contribute.
EDIT: I got it working mostly with the following but the output is messy. Open to suggestions.
# Computer running this script
$ServerList = get-content -path "C:\scripts\ServerList.txt"
$Path = "C:\scripts\results"
foreach ($server in $ServerList)
{
$Results += "Results for $server"
$InstalledApps = Invoke-Command -ComputerName $server -ScriptBlock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* }
$Results += $InstalledApps |
Select DisplayName, DisplayVersion, Publisher, InstallDate |
Out-String
}
# Write-Host $Results
$Results | out-file -filepath "$Path\InstalledPrograms.txt" -width 200
I have a txt file with all the server names.
I want to query each server in the txt to see if RDS is installed. So far it works fine. But the export needs to have servername and the installed role. how can I pass the servername to the output file.
At the moment it is querying but only the installed. so with a 100 servers who really can tell which server has it installed and which doesnt>>>> PLEase help
Import-Module ServerManager
Get-Content W:\AllWindows.txt | ForEach-Object {Get-WindowsFeature -Name Remote-Desktop-Services} | Format-Table -Auto -wrap | Out-File -FilePath $csvfile
Try something like this:
Get-Content W:\AllWindows.txt | ForEach-Object { #(($_), (Get-WindowsFeature -Name Remote-Desktop-Services)) } | Format-Table -Auto -wrap | Out-File -FilePath $csvfile
I have worked it out:
Get-Content W:\windows2012.csv | Foreach-Object {{Get-WindowsFeature | where-object {$_.Installed -eq $True} | Export-Csv -Path "W:\output\$_.txt"}
I would like to compare two Servers registry keys to make sure they both match.
Something simple like this was the initial plan:
$remote1 = (invoke-command -computername hostname `
{Get-ItemProperty "HKLM:SOFTWARE\VENDOR\APP\SUBFOLDER"})
$local1 = (invoke-command `
{Get-ItemProperty "HKLM:SOFTWARE\VENDOR\APP\SUBFOLDER"})
$compare1 = Compare-Object $local1 $remote1
That works great for one single specified key but I have multiple keys with sub folders. I can't provide a list of the ones I want to check (and loop round) as I want to make sure nothing new has been added. So I was drawn down this route to get all the keys under a specified branch in the Registry (to get me a list):
$local1 = Get-ChildItem HKLM:SOFTWARE\MICROSOFT\DirectShow -Recurse `
-ErrorAction SilentlyContinue
So I now have an object that will tell me all the registry SUBFOLDERS on the server and I could then loop round using $local1.PSPath to give me all the paths but I noticed something in the object that was interesting:
$local1 | select -first 1 -prop *
This returns:
Property : {dbl3, dbl4, dbl5, dbl6...}
PSPath : A path
PSParentPath : A Parent Path
PSChildName : 0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
PSIsContainer : True
SubKeyCount : 0
View : Default
Handle : Microsoft.Win32.SafeHandles.SafeRegistryHandle
ValueCount : 8
Name : A Name
So the Object member "Property" contains what looks like an array of all the keys or is it a sub Object?
If it was a sub-object does it contain the keys values that I am looking to compare?
I could just snatch out the $local.Name member and loop round comparing using the code above and storing any differences but I just wondered if it would be more efficient to use the data that I already have if it contains the information I need?
I am hoping that someone could confirm that if I did:
$local1 = Get-ChildItem HKLM:SOFTWARE\MICROSOFT\DirectShow -Recurse `
-ErrorAction SilentlyContinue
$remote1 (invoke-command -computername remoteserver1 `
{Get-ChildItem HKLM:SOFTWARE\MICROSOFT\DirectShow -Recurse `
-ErrorAction SilentlyContinue})
When I do the compare am I actually comparing the keys and values match or just that keys exist? :
Compare-Object $local1 $remote1
To cut a long story short, I think I have all the data I need to compare that the Registry key values match (by running this):
$local1
Returns (extract):
Hive: HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\DirectShow
Name Property
---- --------
Debug
DoNotUse
DoNotUseDrivers32
Preferred {00001602-0000-0010-8000-00aa00389b71} : {E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}
{e06d8032-db46-11cf-b4d1-00805f6cbbea} : {E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}
{00000160-0000-0010-8000-00aa00389b71} : {2eeb4adf-4578-4d10-bca7-bb955f56320a}
{41564D57-0000-0010-8000-00AA00389B71} : {82d353df-90bd-4382-8bc2-3f6192b76e34}
{e06d8026-db46-11cf-b4d1-00805f6cbbea} : {212690FB-83E5-4526-8FD7-74478B7939CD}
Am I correct and does anyone know how to access individual items from the $local1 object? Taking the example above, what is a Hive? Say I wanted the "00001602-0000-0010-8000-00aa00389b71" value how would I get it from the $local1 object.
A point to note that the servers are running Powershell 2 while I am testing on Powershell 4 (I can't test on a Production server). I mention this as running $local1 on the v2 servers I get a different output in that the properties do not seem to be in pairs.
Hive: HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\DirectShow
SKC VC Name Property
--- -- ---- --------
0 0 Debug {}
0 0 DoNotUse {}
0 0 DoNotUseDrivers32 {}
0 10 Preferred {{00000050-0000-0010-8000-00AA00389B71}, {e436eb80-524f-11ce-9f53-0020af0ba77...
Is this case where the v4 objects will do what I want but the v2 won't?
Well fought my way back through the tumble-weed on this one to answer my own question. I had to assume that PowerShell V2 did not contain the key values as I couldn't find a way of extracting them so to be sure I was performing a comparison of the keys and key values I went with this:
foreach ( $KeyPath in $RegPath )
{
$_Path = (invoke-command {Get-ChildItem $KeyPath -Recurse -ErrorAction SilentlyContinue})
ForEach ($key in $_Path)
{
$local = #()
$remote = #()
ForEach ( $Property in $key.Property )
{
if ( $Key.Name -like "*HKEY_LOCAL_MACHINE*" )
{
$KeyPath = [regex]::Replace($key.Name,[regex]"HKEY_LOCAL_MACHINE\\","HKLM:")
} elseif ( $Key.Name -like "*HKEY_CURRENT_USER*" ) {
$KeyPath = [regex]::Replace($key.Name,[regex]"HKEY_CURRENT_USER\\","HKCU:")
} else {
Write-Host "I was unable to set the Registry Hive path, exiting........"
exit 1
}
$lentry = (invoke-command {Get-ItemProperty -Path $KeyPath -Name $Property})
$lfound = New-Object -TypeName PSObject
$lfound | Add-Member -Type NoteProperty -Name Path -Value $KeyPath
$lfound | Add-Member -Type NoteProperty -Name Name -Value $Property
$lfound | Add-Member -Type NoteProperty -Name Data -Value $lentry.$Property
$local += $lfound
$rentry = (invoke-command -computername remoteservername -Script {Get-ItemProperty -Path $args[0] -Name $args[1]} -Args $KeyPath, $Property -ErrorVariable errmsg 2>$null)
if ( $errmsg -like "*does not exist at path*" )
{
$Value = "KEY IS MISSING"
} else {
$Value = $rentry.$Property
}
$rfound = New-Object -TypeName PSObject
$rfound | Add-Member -Type NoteProperty -Name Path -Value $KeyPath
$rfound | Add-Member -Type NoteProperty -Name Name -Value $Property
$rfound | Add-Member -Type NoteProperty -Name Data -Value $Value
$remote += $rfound
}
$compare = Compare-Object -ReferenceObject $local -DifferenceObject $remote -Property Path,Name,Data
$results += $compare
}
}
You then have all the results in an $results object that can be worked on. I used the object in an HTML table similar to this Powershell Hash Table to HTML.
I think it would have been much simpler in PowerShell version four with no need to build $lfound and $rfound.
In powershell v4 you can just export the registry keys at whatever point you want and then use the following to compare them:
$badReg = Get-content C:\Data\badReg.reg
$goodReg = Get-ChildItem C:\Data\goodReg.reg
$results = Compare-Object -ReferenceObject $goodReg -DifferenceObject $badReg
Is there a way in VSTS 2008 to generate a report on the source control in Team Foundation Server, of what are the files that were changed by user: x for last few days?
Do you need a webpage hosted by SQL Reporting Services, or will any reporting mechanism do? Here's a quick & dirty one:
tfhistory $/project -r -all -version D6/10/2009~ | % {
$user = $_.owner
$date = $_.creationdate
$_.changes | % { $_.item } |
add-member noteproperty user $user -passthru |
add-member noteproperty date $date -passthru
} |
sort #{Expression="User";Ascending=$true},#{Expression="Date";Ascending=$false},#{Expression="ServerItem";Ascending=$true} |
select user, date, serveritem |
out-gridview
(requires the Powershell snapin from TFS Power Tools)