Failing to upload file to Azure Fileshare - azure

I am trying to upload a csv file to azure file share. Below is the cmdlets I am using:
$folderPath="/"
$ctx=(Get-AzStorageAccount -ResourceGroupName 'rg-aexch' -Name 'storaexch').Context
$fileShare = Get-AZStorageShare -Context $ctx -Name "fs-aexch"
Set-AzStorageFileContent -Share $fileShare -Source "E:\ Exc\dash\batch1.csv" -Path $folderPath -Force
But I am getting the below error:
Set-AzStorageFileContent : Cannot bind parameter 'Share'. Cannot convert the "Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare" value of type
"Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare" to type "Microsoft.Azure.Storage.File.CloudFileShare".
At line:13 char:37
Set-AzStorageFileContent –Share $s –Source $localFile
~~
CategoryInfo : InvalidArgument: (:) [Set-AzStorageFileContent], ParameterBindingException
FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.SetAzureStorageFileContent

Related

GetEnumerator error whilst running my script

I am trying to extract and export Azure Webapp settings using the below script
$allWebApps = Get-AzureRmWebApp
$resourceGroups = $allWebApps | Select-Object 'ResourceGroup' -Unique
foreach($r in $resourceGroups)
{
$rgName = $r.ResourceGroup
$webApps = Get-AzureRmWebApp -ResourceGroupName $rgName
foreach($w in $webApps)
{
$webAppName = $w.Name
Write-Host Processing Webapp : $webAppName
$webApp = Get-AzureRmWebApp -ResourceGroupName $rgName -Name $webAppName
$appSettings = $webApps.SiteConfig.AppSettings
# Extract AppSettings to CSV
$appSettings.GetEnumerator() |
Sort-Object -Property Name -Descending |
Select-Object -Property #{n='Key';e={$_.Name}},Value |
Export-Csv -Path "C:\Cloud\$webAppName.csv" -NoTypeInformation -Append
}
}
but I keep getting the below error:
You cannot call a method on a null-valued expression.
At C:\Cloud\ExportsWebApp_config.ps1:17 char:9
+ $appSettings.GetEnumerator() |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
can someone please assist?
$appSettings = $webApps.SiteConfig.AppSettings
I think this line should be changed, otherwise you're trying to get the properties of the entire array of web apps.
$appSettings = $webApp.SiteConfig.AppSettings

Set-AzRecoveryServicesAsrVaultContext : Operation failed

Below script works for one recovery vault but fails for another.
Script
$Sub = Get-AzSubscription -SubscriptionName ''
$context = $Sub | Set-AzContext
$rv = Get-AzRecoveryServicesVault -ResourceGroupName '' -Name ''
Set-AzRecoveryServicesAsrVaultContext -Vault $rv -defaultprofile $context
Error
Set-AzRecoveryServicesAsrVaultContext : Operation failed.
Download vault credential file using cmdlet Get-AzRecoveryServicesVaultSettingsFile and Import-AzRecoveryServicesAsrVaultSettingsFile
At line:1 char:1
+ Set-AzRecoveryServicesAsrVaultContext -Vault $rv -defaultprofile $con
+ CategoryInfo : CloseError: (:) [Set-AzRecoveryServicesAsrVaultContext], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.SiteRecover
Hi the issue was related to vnet configuration. now it is resolved.
error was was coming as data was not passing from one vnet to another.

azure cloud powershell runbook upload in storage account

I am uploading the result of some computation to an azure storage account.
I use these statements:
$context = New-AzureStorageContext -StorageAccountName "csb5387a20f4e8cx435ax9b8" -StorageAccountKey "xxxx "
Set-AzureStorageBlobContent -Container "azurescan" -File $FileName -context $context
It has worked and this statments still work on the Cloud Shell.
But in the runbook they get the following error-messages, which are not very helpful.
Can anybody help me?
Set-AzureStorageBlobContent : Method not found:
'System.Net.HttpWebRequest
Microsoft.WindowsAzure.Storage.RequestEventArgs.get_Request()'. At
line:329 char:5
+ Set-AzureStorageBlobContent -Container "azurescan" -File $FileNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureStorageBlobContent], StorageException
+ FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand

Why isn't VScode pwsh terminal able to see my azure resource groups?

I'm trying to tag all my running VMs from azure with tags from a CSV file but my PowerShell script is failing when being run from VSCode PowerShell core terminal.
I double-checked and I have set the correct active subscription (we have multiple tenants and subscriptions), but the output says that it can't find my resource groups (they are there for sure).
Enable-AzureRmAlias
$csv = import-csv "C:\Users\popes\Desktop\Jedox\Powershell scripts\Tagging\Tagging.csv"
$csv | ForEach-Object {
# Retrieve existing tags
$tags = (Get-AzResource -ResourceGroupName $_.RG -ResourceType "Microsoft.Compute/virtualMachines" -Name $_.VM).Tags
# Define new value pairs from CSV
$newTags = #{
company = $_.Company
dns = $_.DNS
type = $_.Type
CN = $_.CN
}
# Add new tags to existing set (overwrite conflicting tag names)
foreach($CN in $newTags.Keys){
$tags[$_] = $newTags[$_]
}
# Update resource with new tag set
Set-AzResource -ResourceGroupName $_.RG -Name $_.VM -Tag $tags -ResourceType "Microsoft.Compute/virtualMachines"
}
The output:
Get-AzResource : Resource group 'machine774_rg' could not be found.
At line:3 char:14
+ ... $tags = (Get-AzResource -ResourceGroupName $_.RG -ResourceType "Mi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzResource], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet
Cannot index into a null array.
At line:15 char:9
+ $tags[$_] = $newTags[$_]
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Try to use Clear-AzContext, then login with specific tenant and subscription, Connect-AzAccount -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy".

I keep getting this error when I'm running PowerShell

When I run this PowerShell script
Import-Module WebAdministration
$path1 = Get-ItemProperty -PSPath IIS:\Sites\CompassSvcQA-Red\R4\CompassSettings
Set-Location "C:\Windows\Microsoft.NET\Framework\v4.0.30319"
.\aspnet_regiis.exe -pef "connectionStrings" $path1.physicalPath -prov "DataProtectionConfigurationProvider"
I'm getting this error:
Get-ItemProperty : Cannot find drive. A drive with the name 'IIS' does
not exist. At line:2 char:10
+ $path1 = Get-ItemProperty -PSPath IIS:\Sites\CompassSvcQA-Red\R4\CompassSettings
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IIS:String) [Get-ItemProperty], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

Resources