Skip to content

Commit 9816610

Browse files
shailja025sihegde
authored andcommitted
Create AzureStorage_Check_whether_SFTP_is_enabled_or_not_and_ifEnabled_list_LocalUsers.ps1
Checks if SFTP is enabled on a specified Azure Storage Account. If enabled, lists all local SFTP users with their username, home directory and permission scopes. Otherwise, it notifies that SFTP is disabled.
1 parent 95dccf7 commit 9816610

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
###ATTENTION: DISCLAIMER###
2+
3+
#DISCLAIMER
4+
#The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, owners of this repository or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including,
5+
#without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages
6+
7+
8+
############################################################# Script Overview #############################################################
9+
########## This script helps to retrieves the storage account properties to verify if SFTP support is enabled or disables. #########
10+
########## If SFTP is enabled, the script fetches and enumerates all local users configured for SFTP access on that specific storage account. #########
11+
########## If no users are found, it notifies accordingly. If SFTP is disabled, the script outputs a clear message indicating that #########
12+
13+
$resourceGroup = "<resource-group>"
14+
$storageAccountName = "<storage-account-name>"
15+
16+
# Login if needed
17+
Connect-AzAccount
18+
19+
# Get storage account details
20+
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
21+
22+
if ($storageAccount.EnableSftp -eq $true) {
23+
Write-Host "SFTP is ENABLED for storage account '$storageAccountName'." -ForegroundColor Green
24+
25+
try {
26+
$localUsers = Get-AzStorageLocalUser -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName
27+
28+
if (-not $localUsers) {
29+
Write-Host "No local SFTP users found." -ForegroundColor Yellow
30+
} else {
31+
Write-Host "`Local SFTP Users:"
32+
Write-Host "-----------------------------"
33+
34+
foreach ($user in $localUsers) {
35+
Write-Host "Username : $($user.Name)"
36+
Write-Host "Home Dir : $($user.HomeDirectory)"
37+
Write-Host "Permissions :"
38+
$user.PermissionScopes | ForEach-Object {
39+
Write-Host " - Permissions: $($_.Permissions), ContainerName: $($_.ResourceName)"
40+
}
41+
Write-Host "-----------------------------"
42+
}
43+
}
44+
}
45+
catch {
46+
Write-Host "Error retrieving local users. Ensure your Az.Storage module supports SFTP." -ForegroundColor Red
47+
Write-Host "Detailed error: $_" -ForegroundColor Red
48+
}
49+
}
50+
else {
51+
Write-Host "SFTP is DISABLED for storage account '$storageAccountName'." -ForegroundColor Red
52+
}

0 commit comments

Comments
 (0)