install OMS Log Analytics Agent and OMS Dependency Agent to all Windows VMs in the subscription using PowerShell

Save the following code as myscript.ps1 by replacing the ????? with the OMS workspaceid and OMS workspace key. Share the file using Storage Account Shared Access key as https:// function installOMS { param( [parameter(Mandatory=$true, HelpMessage=”OMS Log Analytics Workspace ID”)] [ValidateNotNullOrEmpty()] [string]$WorkSpaceID, [parameter(Mandatory=$true, HelpMessage=”OMS Log Analytics Workspace Key”)] [ValidateNotNullOrEmpty()] [string]$WorkSpaceKey ) $verboseactionoutput = “continue” # Set…

2

Post data to OMS Log Analytics Data Collector API using PowerShell

# Create the function to create and post the request Function Post-OMSData($customerId, $sharedKey, $body, $logType) { $method = “POST” $contentType = “application/json” $resource = “/api/logs” $rfc1123date = [DateTime]::UtcNow.ToString(“r”) $contentLength = $body.Length $signature = Build-Signature ` -customerId $customerId ` -sharedKey $sharedKey ` -date $rfc1123date ` -contentLength $contentLength ` -fileName $fileName ` -method $method ` -contentType $contentType…

0

The difference between [Switch] and[Bool] in Powershell function parameters

#switch parameter cls function MyAwesomeFunction1 { [CMDLetBinding()] param ( [string] $foo, [string] $bar, [switch] $someVariable ) Write-Host “someVariable = $someVariable” + $someVariable.GetType() if($someVariable) { Write-Host $foo } else { Write-Host $bar } } #boolean parameter function MyAwesomeFunction2 { [CMDLetBinding()] param ( [string] $foo, [string] $bar, [bool] $someVariable ) Write-Host “someVariable = $someVariable” + $someVariable.GetType() if($someVariable)…

4

How to deploy OMS Log Analytics Agent and Dependency Agent using DSC

# replace the ??????????? in the script Configuration MMAgent { $OIPackageLocalPath = “$env:temp\MMASetup-AMD64.exe” $SMapPackageLocalPath = “$env:temp\InstallDependencyAgent-Windows.exe” $OPSINSIGHTS_WS_ID = “??????????????” $OPSINSIGHTS_WS_KEY = “??????????????” Import-DscResource -ModuleName xPSDesiredStateConfiguration Node SQLnode { } Node OMSnode { Service OIService { Name = “HealthService” State = “Running” DependsOn = “[xPackage]OMSAgent” } Service DependencyService { Name = “MicrosoftDependencyAgent” State = “Running” DependsOn…

0

How to deploy OMS Log Analytics Agent and Dependency Agent to thousands of computers using PowerShell Workflow in parallel

workflow installOMS{ #fill in the computers.txt in temp folder as one computer per line with no delimeters $computers = inlinescript { $BaselineFile = “$env:temp\computers.txt” $lines = (Get-Content $BaselineFile) $computers = foreach ($line in $lines) { $line.Trim()} return $computers } parallel { inlinescript { try { $OPSINSIGHTS_WS_ID = “??????” $OPSINSIGHTS_WS_KEY = “?????” $arg1 = ‘/C:”setup.exe /qn…

0

Create new user via Microsoft Graph using PowerShell

cls # Load Active Directory Authentication Library (ADAL) Assemblies $adal = “${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll” $adalforms = “${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll” [System.Reflection.Assembly]::LoadFrom($adal) [System.Reflection.Assembly]::LoadFrom($adalforms) $cred = Get-Credential $mycred = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential($cred.UserName,$cred.Password) # Defining Azure AD tenant name, this is the name of your Azure Active Directory $adTenant = ”??????.onmicrosoft.com” $login = Add-AzureRmAccount -Credential $cred Get-AzureRmSubscription Select-AzureRmSubscription -SubscriptionID ‘??????‘ # Set…

0

user management using the AzureAD powershell module

cls $cred = Get-Credential #Connect to your AzureAD tenant Connect-AzureAD -Credential $cred # Get a user by UPN $user = Get-AzureADUser -ObjectId “user1@????.onmicrosoft.com” $user | fl # Update some properties $user = Set-AzureADUser -ObjectId $user.UserPrincipalName -Department “Azure Architecture” -Country “Turkey” # Get a user by UPN $user = Get-AzureADUser -ObjectId “user1@????.onmicrosoft.com” $user | fl

1