0

我试图找出最佳方法来实现将我的 csv 从以下脚本导出到我的存储 blob 容器的方法。下面的脚本将仅在 Azure Runbook 中使用。有谁知道或可以帮助我将导出 csv 实现到 blob 容器中的最佳方法?

$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
$a = "---------------------------------------------------------------------------------------- 
--------------------------"            
$vnetObjs = Get-AzVirtualNetwork 
foreach ($vnetobj in $vnetObjs) {
$resultvNet = "vNet Name: " + $vnetObj.Name
$resultvNet
$resultPeering = "Peering: " + (Get-AzVirtualNetworkPeering -Name "*" -VirtualNetwork 
$vnetObj.Name -ResourceGroupName $vnetobj.ResourceGroupName | Select-Object -ExpandProperty 
Name)
$resultPeering
if ($vnetobj.DhcpOptions.DnsServers){
$resultDNS = "DNS Server: " + $vnetobj.DhcpOptions.DnsServers
}
else {
$resultDNS = "DNS Server: Azure Default" 
}
$resultDNS
$resultIPAddress = $vnetobj | Get-AzVirtualNetworkSubnetConfig | Select-Object 
Name,AddressPrefix
$resultIPAddress
$a 
}    
foreach ($user in $users){
write $user
$user | export.csv $FileName -NoTypeInformation -Append
}
$StorageURL = "https://TESTTEST.blob.core.windows.net/TESTTEST1234/"
$FileName = "export.csv"
$SASToken = "sp=racwdl&st=2021-06-20T15:22:29Z&se=2022-07-01T23:22:29Z&sv=2020-02- 
10&sr=c&sig=SwBLIW%2FEfmjeNjMUHtPsO6Ad2frC8egXNwEPvN6h8gY%3D"

$blobUploadParams = @{
URI = "{0}/{1}?{2}" -f $StorageURL, $FileName, $SASToken
Method = "PUT"
Headers = @{
'x-ms-blob-type' = "BlockBlob"
'x-ms-blob-content-disposition' = "attachment; filename=`"{0}`"" -f $FileName
'x-ms-meta-m1' = 'v1'
'x-ms-meta-m2' = 'v2'
}
Body = $Content
Infile = $FileToUpload
}
4

0 回答 0