Manage Azure classic storage accounts using the RM mode - azure-powershell

I am only using the new RM mode with PowerShell. Although I see all the storage cmdlets, but they do not seem to work with the classic storage accounts.
If I run these two commands, no account are returned:
Get-AzureRmSubscription –SubscriptionName "mysubs | Select-AzureRmSubscription
Get-AzureRmStorageAccount -ResourceGroupName "myrg"
Also....if I try this command:
Set-AzureRmStorageAccount -ResourceGroupName "myrg" -Name "myaccount" -Type Standard_GRS
It says no storage account exists. I think it is only looking for new storage accounts which I don't have any.
Is there a way to force the RM storage module to retrieve/manager classic storage accounts?
Regards

I don't think I can. So I used the following non-RM Cmdlts and it worked fine:
Add-AzureAccount
Select-AzureSubscription -SubscriptionName $subscription
Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $storageAccount
Get-AzureStorageBlob -Container $containerName
Get-AzureStorageBlob -Container $containerName | Export-Csv $csv -NoTypeInformation -Encoding UTF8 -Delimiter ','

Related

Add-AzTableRow command is not available in Azure Cloud Shell

I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert.
Blockquote
Add-AzTableRow: The term 'Add-AzTableRow' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Blockquote
Below are the command:
$partitionKey1 = "partition1"
$partitionKey2 = "partition2"
Add-AzTableRow `
-table $cloudTable `
-partitionKey $partitionKey1 `
-rowKey ("CA") -property #{"username"="Chris";"userid"=1}
According to the error, it seems that you do not install the module AzTable. Please run the command Get-InstalledModule to check if you have installed the module.
If you have not installed the module, please run the command Install-Module -Name AzTable -Force to install it.
For example
Install-Module -Name AzTable -Force
Import-Module AzTable
$resourceGroup = "<your group name>"
$storageAccountName ="<your account name>"
$storageAccount=Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
$ctx = $storageAccount.Context
$tableName = "<table name>"
$cloudTable = (Get-AzStorageTable –Name $tableName –Context $ctx).CloudTable
$partitionKey1 = "partition1"
Add-AzTableRow -table $cloudTable -partitionKey $partitionKey1 -rowKey ("CA") -property #{"username"="Chris";"userid"=1}

Automatic extract zipped files with passwords in the file name

I analyse data from being sent multiple ZIP files.
They are always in this format:
service_SC30COM_####_20191130_1834.zip
#### is a random number generated by the computer.
Password is SC30COM_####, which is always part of the file name.
Any suggestions on an automation to unzip in bulk?
There is no way to do it on the command prompt without any application.
You can check this
If your remove the password, the code you need, as explain in that microsoft article should be:
$shell=new-object -com shell.application
$CurrentLocation=get-location
$CurrentPath=$CurrentLocation.path
$Location=$shell.namespace($CurrentPath)
$ZipFiles = get-childitem *.zip
$ZipFiles.count | out-default
foreach ($ZipFile in $ZipFiles)
{
$ZipFile.fullname | out-default
$ZipFolder = $shell.namespace($ZipFile.fullname)
$Location.Copyhere($ZipFolder.items())
}
If you install any application that can run on command prompt, you can extract with password. As example, for a individual file, the maximum you will get on Windows 10 is:
PowerShell Expand-Archive -Path "C:\Users\Tuffy\Desktop\PowerShell
Expand-Archive -Path "C:\Users\Whatever\Desktop\service_SC30COM_####_20191130_1834.zip"
-DestinationPath "C:\Users\Whatever\Desktop"p" -DestinationPath "C:\Whatever\Tuffy\Desktop"
Hope it helps!
You can run the following code as a bash script:
#!/bin/bash
for FILE in *.zip
do
echo "Unzipping $FILE ..."
PASSWORD=$(echo $FILE | grep -o -P '(?<=service_)[A-Za-z0-9]*_[0-9]*(?=_)')
unzip -P $PASSWORD $FILE
done
Copy the code
Paste it into FILENAME.sh
Make it executable (chmod +x FILENAME.sh)
Put it besides the zip files
Run it (./FILENAME.sh)

Automating Folder creation in Azure Data Lake Store (Gen2)

Is there any way we can automate Folder creations in ADLS Gen2 pragmatically. It is required for doing this in Production Subscription on which there is limited access from Portal.
If there is any suggestions, please help on this.
For the benefit of broader audience re-sharing Ivan Yang's comment as answer i.e.,.
You can use the rest api here
You could use Azure cli for this, but it is still in preview.
#add the extension
az extension add --name storage-preview
# Create Directory
$dirCheck = az storage blob directory exists -c $filesystemName -d $dirname --account-name $storageaccountname --debug
$exists = $dirCheck | ConvertFrom-Json
If (-Not $exists.exists[0])
{
az storage blob directory create -c $filesystemName -d $dirname --account-name $storageaccountname
}

Get-AzScheduledQueryRule what is same funtion script for azurerm

In az Get-AzScheduledQueryRule but in azurerm there is no query rule. I f any alternative script means pls share.
Well, the Get-AzScheduledQueryRule command gets the alert rule whose SIGNAL TYPE is Log Search, its resource type is microsoft.insights/scheduledqueryrules.
For the AzureRM module, your option is to use the Get-AzureRmResource command, specify the -ResourceType with "microsoft.insights/scheduledqueryrules".
Sample:
Get-AzureRmResource -ResourceGroupName "<ResourceGroupName>" -ResourceType "microsoft.insights/scheduledqueryrules" -Name "<alert rule name>" | ConvertTo-Json

gwmi win32_service -ComputerName IP –credential userName returns Access denied but Enter-PSSession -ComputerName IP -Credential Personal works

Running this powershell command
Enter-PSSession -ComputerName 192.168.1.184 -Credential Personal
command works fine. The username and password is accepted.
Again, running this command:
Invoke-Command -ComputerName 192.168.1.184 -ScriptBlock { Get-ChildItem C:\ } -credential Personal
Also works fine and it displays the folders in drive C. It also implies that i can login. When i run this command:
gwmi win32_service –credential Personal –computer 192.168.1.184
I get "gwmi : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
So does this:
Copy-Item -Path c:\d\test.txt -Destination \\192.168.1.184\c$\dep\test.txt
I've tried everything i could think of and i still fail. My goal is to copy files to target computers and execute these files. I have about 52 machines and i need to be able to install these programs.
Anyone knows why this isn't working?