April 19, 2018

ReFS - High RAM usage

How to identify and fix high RAM usage on Windows Server 2016 due to ReFS? 

As you can see from Task Manager, 5GB is allocated in non-paged pool. This memory is used by kernel and device drivers.

This also can be checked by RamMap tool.

Use poolmon.exe tool from WDK to identify what components are using most of memory. Run "poolmon.exe -u -p" in elevated command prompt. 

Then use findstr tool to find out what device drivers are under MSb+, MSde and MStb tags. Simply run "findstr /m /l /s MSb+ *.sys". Replace Tag name for each search.

As you can see 4.5GB is allocated by ReFS component. This behavior is expected and fixed by KB4013429. More details can be found in here.

April 11, 2018

Azure - Find empty Resource Groups

How to identify empty Resource Groups in Microsoft Azure using PowerShell?
$AllRGs = (Get-AzureRmResourceGroup).ResourceGroupName
$RGsWithResources = (Get-AzureRMResource | Group-Object ResourceGroupName).Name
$AllRGs | Where-Object {$_ -notin $RGsWithResources}

Azure AD Connect - Change UPN

How to change User Principal Name attribute for synchronized user?

Set-MsolUserPrincipalName -UserPrincipalName "name@example.com" -NewUserPrincipalName "newname@example.com"

Note: “User Account Administrator” role is enough to perform this action.

Alternatively, you can enable UPN synchronization via SynchronizeUpnForManagedUsers feature:

Set-MsolDirSyncFeature -Feature SynchronizeUpnForManagedUsers -Enable $True

After activating this feature, when you change UPN on premises it will sync all the changes to the Office 365.

March 3, 2018

Azure - Change Blob Tier script

Simple PowerShell script to set Archive Access Tier for all Blobs older than 1 month in a specific storage account.

$StorageAccount = "Your SA Name"
$StorageAccountKey = "SA Key"
$ContainerName ="Container Name"
$Context = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey
$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context
Foreach ($Blob in $Blobs | where {$_.LastModified -lt (Get-Date).AddMonths(-1)})

Or run $Blobs.ICloudBlob.SetStandardBlobTier("Archive")” instead Foreach” loop to set all blobs.

February 26, 2018

SSH Port Forwarding example

In addition to my previous post about SSH tunneling. Here is another example of accessing web server in a restricted network. Plink.exe command-line tool will be used on Windows admin computer to access SSH Server.

February 19, 2018

Microsoft Azure - Migrate from classic to ARM

In this post I show how to migrate supported IaaS resource from classic deployment model to Azure Resource Manager. PowerShell will be used to achieve this task. Make sure that you are an administrator for your Azure subscription and your Azure region has enough available vCPUs resources (refer to ARM limits).

Items for migration:
TestRG1 - Virtual network (classic)
Testrg1sa - Storage account (classic)
TestVm1 - Virtual machine (classic)
TestVM19796 - Cloud service (classic)

February 16, 2018

PowerShell - Query MS SQL Server

This PowerShell script connects to SQL server, queries needed data, exports the results to the CSV file and then sends it via email.

# SQL Server connection string details, integration authentication is used.
$SQLConnectionString = "Server=SQLSERVER\InstanceName;Database=DatabaseName;Integrated Security=SSPI"
# Path to the file for exported data.
$File = "C:\Script\file.csv"
# SQL Query syntax itself.
$SQLQuery = "
select * from DB_Table_Name

January 29, 2018

PowerShell - Generate GUID

This PowerShell script uses NewGuid() method of the .Net Framework guid class to generate a Globally Unique Identifier. You can generate 1 GUID by running the script or specify how many GUID’s you want. See example below.

PS C:\> .\generate-guid.ps1

PS C:\> .\generate-guid.ps1 3

January 16, 2018

PowerShell - Monitoring Windows Service

This PowerShell script checks specific Windows Service. If service is in a stopped state script starts it and creates a log file.

Script usage example:
.\MonitorWindowsService.ps1 -ServiceName "SNMP Trap" -IntervalSeconds 30

Script above checks SNMP Trap service every 30 seconds. Any changes to the service state will be logged in “SNMP Trap_log.txt” file.

December 19, 2017

Office 2016 ProPlus - First Run ADMX

Some policy settings which are not included in a default Office 2016 ADMX file. The policy allows accepting all first run popups and disables default file type selection (XML/OpenDocument) during first run. Both files can be downloaded in a single archive here.