@@ -310,57 +310,50 @@ Set this parameter so that no sign-in occurs -- you must sign in first. Use this
310
310
This command produces only STDOUT output (not standard PowerShell) with information about affect accounts.
311
311
#>
312
312
param(
313
- [boolean ]$BypassConfirmation= $false,
314
- [Parameter(Mandatory= $true, ValueFromPipelineByPropertyName= 'SubscriptionId') ]
313
+ [boolean ]$BypassConfirmation = $false,
314
+ [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = 'SubscriptionId') ]
315
315
[String ] $SubscriptionId,
316
316
[switch ] $ReadOnly, # Use this if you don't want to make changes, but want to get information about affected accounts
317
317
[switch ] $NoSignin # Use this if you are already signed in and don't want to be prompted again
318
318
)
319
319
320
320
begin {
321
321
if ( ! $NoSignin.IsPresent ) {
322
- login-azaccount | out-null
322
+ Login-AzAccount | Out-Null
323
323
}
324
324
}
325
325
326
326
process {
327
327
try {
328
- select-azsubscription -subscriptionid $SubscriptionId -erroraction stop | out-null
329
- } catch {
330
- write-error "Unable to access select subscription '$SubscriptionId' as the signed in user -- ensure that you have access to this subscription." -erroraction stop
328
+ Select-AzSubscription -SubscriptionId $SubscriptionId -ErrorAction Stop | Out-Null
329
+ }
330
+ catch {
331
+ Write-Error "Unable to access select subscription '$SubscriptionId' as the signed in user -- ensure that you have access to this subscription." -ErrorAction Stop
331
332
}
332
333
333
- foreach ($account in Get-AzStorageAccount)
334
- {
335
- if($account.AllowBlobPublicAccess -eq $null -or $account.AllowBlobPublicAccess -eq $true)
336
- {
334
+ foreach ($account in Get-AzStorageAccount) {
335
+ if ($null -eq $account.AllowBlobPublicAccess -or $account.AllowBlobPublicAccess -eq $true) {
337
336
Write-host "Account:" $account.StorageAccountName " isn't disallowing public access."
338
337
339
338
if ( ! $ReadOnly.IsPresent ) {
340
- if(!$BypassConfirmation)
341
- {
339
+ if (!$BypassConfirmation) {
342
340
$confirmation = Read-Host "Do you wish to disallow public access? [y/n]"
343
341
}
344
- if($BypassConfirmation -or $confirmation -eq 'y')
345
- {
346
- try
347
- {
348
- set-AzStorageAccount -Name $account.StorageAccountName -ResourceGroupName $account.ResourceGroupName -AllowBlobPublicAccess $false
342
+ if ($BypassConfirmation -or $confirmation -eq 'y') {
343
+ try {
344
+ Set-AzStorageAccount -Name $account.StorageAccountName -ResourceGroupName $account.ResourceGroupName -AllowBlobPublicAccess $false
349
345
Write-Host "Success!"
350
346
}
351
- catch
352
- {
353
- Write-output $_
347
+ catch {
348
+ Write-Output $_
354
349
}
355
350
}
356
351
}
357
352
}
358
- elseif($account.AllowBlobPublicAccess -eq $false)
359
- {
360
- Write-Host "Account:" $account.StorageAccountName " has public access disabled, no action required."
353
+ elseif ($account.AllowBlobPublicAccess -eq $false) {
354
+ Write-Host "Account:" $account.StorageAccountName "has public access disabled, no action required."
361
355
}
362
- else
363
- {
356
+ else {
364
357
Write-Host "Account:" $account.StorageAccountName ". Error, please manually investigate."
365
358
}
366
359
}
0 commit comments