Getting error "Could not find file 'C:\Temp\kn1slgbc.eqj\Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob'."

DeHaven Graham 106 Reputation points
2022-05-19T03:27:16.663+00:00

I'm getting an error in runbooks when I try to Import my csv to import subnets into a Vnet but I'm getting the following error and below that is my code.
" Could not find file 'C:\Temp\kn1slgbc.eqj\Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob'. "

#--------------Connect Azure Run As Account--------------#

$connectionName = "AzureRunAsConnection"
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
    "Logging in to Azure..."
    Add-AzAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 

$StorageAccountName = "appstore40008989"
$ContainerName = "data"
$ResourceGroupName = "powershell-grp"

$key = (Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName)[0].Value
$Context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $key
#$Context
$Container = Get-AzStorageContainer -Name $ContainerName -Context $Context
#$Container
$StorageAccount = Get-AzStorageAccount -Name $StorageAccountName -ResourceGroupName $ResourceGroupName
#$StorageAccount

#CSV File Path 
$CsvFile = Get-AzStorageBlobContent -Blob "DMZTestCSV.csv" -Container $ContainerName -Destination $env:temp -Context $Context -Force
$CsvFile

#Import CSV Data
$CsvData = Import-Csv "$CsvFile"
$CsvData

$ErrorActionPreference = "stop"

$VnetName = "testsubnet"
$VnetObj = Get-AzVirtualNetwork -Name "$VnetName" -ResourceGroupName "$ResourceGroupName"
$VnetObj

foreach ($Rec in $CsvData){

    $subnetname = $Rec.Subnets
    $addressPrefix = $Rec.AddressPrefix
    $nsg = $Rec.NSG
    $rt = $Rec.RouteTable

    $nsgObj = Get-AzNetworkSecurityGroup -Name "$nsg"
    $rtObj = Get-AzRouteTable -name "$rt"


    try { 
            Add-AzVirtualNetworkSubnetConfig -Name "$subnetname" `
                                     -VirtualNetwork $VnetObj `
                                     -AddressPrefix "$addressPrefix" `
                                     -NetworkSecurityGroup $nsgObj `
                                     -RouteTable $rtObj  -WarningAction Ignore |Out-Null

                                     $VnetObj | Set-AzVirtualNetwork | Out-Null

                                     Write-Host "$subnetname : added successfully" -ForegroundColor Green
        }
    catch{
        Write-Host "An error occurred while adding '$subnetname' . please review" -ForegroundColor Red
        $VnetObj = Get-AzVirtualNetwork -Name "$VnetName" -ResourceGroupName $ResourceGroupName
    }

}
Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,762 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
Developer technologies | .NET | .NET Runtime
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,426 Reputation points Moderator
    2022-05-22T10:42:46.647+00:00

    Hi @DeHaven Graham ,

    In your runbook, you would have to change line number 29 from

    $CsvData = Import-Csv "$CsvFile"  
    

    to

    $CsvData = Import-Csv ($env:temp+'\DMZTestCSV.csv')  
    

    because $CsvFile variable just holds the AzureStorageBlob object as mentioned here but not the actual file content that you have downloaded.

    204297-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.