Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaido Järvemets Kaidja

View GitHub Profile
View AD local query
#Query AD tiering level from AD
Function Get-ADTieringLevel
{
Param(
$ServerName
)
$OU = ([adsisearcher]"(&(name=$ServerName)(objectClass=computer))").FindOne().path
View Add AMA Extension
#Add the AMA Extension - this may take a few minutes to run
$AMAExtension = @{
Name = "AMAWindows"
ExtensionType = "AzureMonitorWindowsAgent"
Publisher = "Microsoft.Azure.Monitor"
ResourceGroupName = $ResourceGroup
MachineName = $ServerName
Location = $Location
View Remove session
#Remove PowerShell session
Remove-PSSession -Session $PSRemoteSession
View Onboard new servers remotly
#Onboard new server remotly
$ADTieringLevel = Get-ADTieringLevel -ServerName $ServerName
$Tags = @{
"ADTieringLevel" = $ADTieringLevel;
}
$ResourceGroup = "RG-PROD-IT-AZURE-ARC-WE"
$Location = "West Europe"
View PowerShell remote session
#Get the credentials and open a remote session
$ServerName = ("SRV02").ToUpper()
$Credentials = Get-Credential
$PSRemoteSession = New-PSSession -ComputerName $ServerName -Credential $Credentials
Write-Output "PowerShell remote session status: $($PSRemoteSession.State)"
View Query local AD
#Query AD tiering level from AD
Function Get-ADTieringLevel
{
Param(
$ServerName
)
$OU = ([adsisearcher]"(&(name=$ServerName)(objectClass=computer))").FindOne().path
View Connect Azure
#Connect Azure
Connect-AzAccount
#You may need to change the subscription co next(OPTIONAL)
Set-AzContext -Subscription XXXXX-XXXXX-XXXX-XXXX-XXXXXXX
View Install Az.ConnectMachine module
Install-Module -Name Az.ConnectedMachine -Force -Verbose
View AMA Extension
Name Location ProvisioningState
---- -------- -----------------
AMAWindows westeurope Succeeded
View Azure Arc on-boarding
time="2021-09-18T21:01:35+03:00" level=info msg="Onboarding Machine. It usually takes a few minutes to complete. Sometimes it may take longer depending
on network and server load status."
time="2021-09-18T21:01:35+03:00" level=info msg="Check network connectivity to all endpoints..."
time="2021-09-18T21:01:36+03:00" level=info msg="All endpoints are available... continue onboarding"
time="2021-09-18T21:01:46+03:00" level=info msg="Successfully Onboarded Resource to Azure" VM Id=XXXXX-XXXX-XXXX-XXXX-XXXXXXXX
Get-AzConnectedMachine : The Resource 'Microsoft.HybridCompute/machines/ SRV02' under resource group 'RG-PROD-IT-AZURE-ARC-WE' was not found. For more
details please go to https://aka.ms/ARMResourceNotFoundFix
At C:\Program Files\WindowsPowerShell\Modules\Az.ConnectedMachine\0.2.0\custom\Connect-AzConnectedMachine.ps1:250 char:9
+ Get-AzConnectedMachine -Name $Name -ResourceGroupName $Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~