如何解决Azure 自动化运行手册中的 Powershell 转录文件停止转录错误 - 主机当前未转录 错误行Test_createfile_withlog.ps1详细日志记录输出成绩单文件为空仅限默认成绩单信息示例脚本文件输出这是目标
我正在运行一个非常简单的 Powershell Runbook 脚本,以验证我可以捕获数据数组、导出到 CSV 文件以及将 CSV 文件写入 Azure blob。我还想捕获成绩单并将其写入 Blob。在本地一切正常。在 Azure 中一切正常(除了编写成绩单)。
注意:正斜杠可能看起来很奇怪 (/
)。但是两个输出文件都使用该语法,所以这不是问题。并且此文件 (-Blob "Logs/$Transcript_file"
) 绝对需要将文件写入 azure blob 中的虚拟子文件夹。该文件实际上是正确创建的;但它是空的,不包含成绩单信息。
此外,与 az 自动化相比,Start-Transcript
cmdlet 与我从我的 PC 工作站运行的工作副本的版本相同。
有人能看出什么问题吗?或者基本上如何在 Azure powershell Runbook 中输出脚本文件?
错误行
停止转录:停止转录时发生错误:主机 目前未转录。行:55 字符:1 + 停止转录 + ====== 类别信息:无效操作:(:) [Stop-Transcript],PSInvalidOperationException +fullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.StopTranscriptCommand
Test_createfile_withlog.ps1
<#------------------------------------------------------
# 4,REPORT: Export list of all workspace reports
#
# Create text file with list of fruits. Export to blob storage.
#------------------------------------------------------#>
# -------- Azure Connection --------
# Ensures you do not inherit an AzContext in your runbook
disable-AzContextAutosave -Scope Process
$connection = Get-AutomationConnection -Name AzureRunAsConnection
# Wrap authentication in retry logic for transient network failures
$logonAttempt = 0
while(!($connectionResult) -and ($logonAttempt -le 10))
{
$logonAttempt++
# Logging in to Azure...
$connectionResult = Connect-AzAccount `
-ServicePrincipal `
-Tenant $connection.TenantID `
-ApplicationId $connection.ApplicationID `
-CertificateThumbprint $connection.CertificateThumbprint
Start-Sleep -Seconds 30
}
$AzureContext = Get-AzSubscription -SubscriptionId $connection.SubscriptionID
# -------- Export files to Azure blob --------
$Transcript_file = "test_FritsLog.txt"
$Reports_file = "test_FruitsList.csv"
# Get key to storage account,Map to the reports BLOB context.
$acctKey = (Get-AzStorageAccountKey -Name "myblob" -ResourceGroupName "myResourcegroup").Value[0]
$storageContext = New-AzStorageContext -StorageAccountName "myblob" -StorageAccountKey $acctKey -Verbose
#### Print write-host to log file
Start-Transcript -Path "$Env:temp/$Transcript_file" -verbose
Write-Host "Today: ($Date).ToString("yyyy.MM.dd")"
#-------- PBI Workspace Reports -------
$wsReportsAll = @("apples","bananas","oranges")
$wsReportsAll | SELECT Id,Name,WorkspaceId,Workspace,DatasetId | ft -auto
$wsReportsCsv = ($wsReportsAll | ConvertTo-Csv -NoTypeinformation).ToString()
$wsReportsAll | Export-csv "$Env:temp/$Reports_file"
# $wsReportsAll | Export-csv -Path $Reports_file -NoTypeinformation
Set-AzStorageBlobContent -File "$Env:temp/$Reports_file" -Container "testfolder" -BlobType "Block" -Context $storageContext -Force -Verbose
Stop-Transcript
Set-AzStorageBlobContent -File "$Env:temp/$Transcript_file" -Container "testfolder" -Blob "Logs/$Transcript_file" -BlobType "Block" -Context $storageContext -Force -Verbose
#****************
#****************
详细日志记录
时间类型详情
"2021-05-13T21:29:31.023Z" 6 - 在目标 "C:\Users\Client\Temp\test_FritsLog.txt" 上执行操作 "Start-Transcript"。
"2021-05-13T21:29:31.123Z" 2 - 脚本开始,输出文件为 C:\Users\Client\Temp/test_FritsLog.txt
"2021-05-13T21:29:33.358Z" 4 - 停止转录时发生错误:宿主当前未转录。
'fritslog.txt' 的日志
时间类型详情
“2021-05-13T21:29:31.023Z” 6 在目标“C:\Users\Client\Temp\test_FritsLog.txt”上执行“Start-Transcript”操作。
"2021-05-13T21:29:31.123Z" 2 Transcript 开始,输出文件为 C:\Users\Client\Temp/test_FritsLog.txt
"2021-05-13T21:29:33.443Z" 6 对目标“Logs/test_FritsLog.txt”执行“Set”操作。
"2021-05-13T21:29:33.598Z" 1 将文件 'C:\Users\Client\Temp\test_FritsLog.txt' 上传到容器 'testfolder' 中的 blob 'Logs/test_FritsLog.txt'。
输出成绩单文件为空(仅限默认成绩单信息)
**********************
Windows PowerShell transcript start
Start time: 20210513210351
Username: LsaSetupDomain\Administrator
RunAs User: LsaSetupDomain\Administrator
Machine: CLIENT (Microsoft Windows NT 6.2.9200.0)
Host Application: \orchestrator\orchestrator.SandBox.exe SandBoxId 15a308fe-2cb6-41a8-996f-4f34ca34f135 WithPersistence True StoreFormattedStreams True UseLanguageConstraints False MaxRunningJobsPerSandBox 10 SandBoxHubEndpoint net.tcp://10.218.0.30:30000/AzureRunbookWorker/26/SandBoxManager/e825cb05-9c57-4385-b36d-249d4e61fd5b Cookie 12645944940256590187 CertificateThumbprint 4D5FC29749FD54494966CC573D8D67F9CA1D4849 WritableRootDirectory C:\ ActivitiesDirectory C:\orchestrator\OaaS ModulesDirectory C:\Modules JobevictionIsEnabled True JobevictionIntervalInSeconds 10800 nopersistevictionsLimitIsEnabled True nopersistevictionsLimit 3 DelayFirstKeepAliveMilliseconds 3000 SandBoxKeepAliveIntervalInSeconds 15 AssetManagementEndpoint http://127.0.0.1:40053 UpdateCertificateStore True TraceOptions UseTraceProxy JobRuntimeDataServiceUri https://cus-jobruntimedata-prod-su1.azure-automation.net/ SandBoxHubDnsIdentity jobservice.cus.azure-automation.net TimeOfStartProcess 637565362688768941 IsRemoteSandBox False SignatureCheck None InstallModules False
Process ID: 28
Psversion: 5.1.15063.726
PSEdition: Desktop
PSCompatibLeversions: 1.0,2.0,3.0,4.0,5.0,5.1.15063.726
BuildVersion: 10.0.15063.726
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
**********************
Windows PowerShell transcript end
End time: 20210513210351
**********************
示例脚本文件输出(这是目标)
**********************
Windows PowerShell transcript start
Start time: 20210513171109
Username: computer\first.name
RunAs User: computer\first.name
Configuration Name:
Machine: GWVCP73 (Microsoft Windows NT 10.0.18363.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe -noprofile
Process ID: 7288
Psversion: 5.1.18362.145
PSEdition: Desktop
PSCompatibLeversions: 1.0,5.1.18362.145
BuildVersion: 10.0.18362.145
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started,output file is C:\Users\BRIAN~1\AppData\Local\Temp/testfun_reports.txt
Today: ().ToString( yyyy.MM.dd)
PBI credentials ...
Environment : Public
TenantId : aaa-aaa-aaa-aaa-aaa-aaa
ClientId : company@name.com
Password : ********
Workspace info ...
1 workspace count
BI Reports Documentation...
17 report count
Id Name WorkspaceId Workspace
-- ---- ----------- ---------
60ecc181-edbf-4bb1-9a13-2dbd72013543 PIPELINE - Pipeline Billing Process Report 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
8897828e-2cf6-4dcb-a238-b76d0dd2b444 PIPELINE - Customer Daily Reports 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
bd322299-8dfa-4d7d-a98a-0ec27e439de2 PIPELINE - Customer vs Plow Daily Variance Report 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
aab4d591-d40a-480a-83d7-8e6ba4a9b4c4 ALL COMPANY - Global Daily Volume 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
d04e4ce6-facc-4f5c-967f-3660a3f7037e ALL COMPANY - Historical Volume - Lookback 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
4eb54d6c-6139-449c-805f-3684dffe09f2 ALL COMPANY - Volumes by disposal 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
275d1301-f7ae-4260-9d7a-6cbc83685c6b CONFIDENTIAL - Total Revenue by Entity 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
794b83d4-9d6e-4da7-a017-613ec986dcf9 CUSTOMER REPORTS - 3rd Party Operators 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
cdc44e2d-e77a-4b46-ab36-68af3f13c445 CUSTOMER REPORTS - Field Ticket Caspio Import Report 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
5daabf87-7b43-4f44-b325-8f34b9eae455 TRUCKING - Aging eApproval Tickets 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
58fa19f2-3392-441f-be26-a504a6153922 TRUCKING - BTG Customer BIlling 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
cece80c8-9ba2-4853-a7cf-e6d03feaec3a TRUCKING - Eticket Barrel Volumes 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
33746ba9-fc03-4d19-b287-6e5e5873646a TRUCKING - ETicket Billing 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
54722dfe-4249-4d7c-8224-ffd3998e165b TRUCKING - Logistics KPI's 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
363a87da-b5e7-4de3-b787-3a4eb80c61cb PIPELINE - Pipeline Meter Management Report 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
bb816086-4587-48b7-971c-2301192b971c ALL COMPANY - Bison KPIs 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
7a9fda56-89a1-469d-af28-49f0bc47e5de TRUCKING - Ticket Tracking & Trouble shooting 0ae6a03f-fbd2-4ff4-89d8-1399188297a9 BI Repor...
VERBOSE: Performing the operation "Set" on target "".
VERBOSE: Transfer Summary
--------------------------------
Total: 1.
Successful: 1.
Failed: 0.
**********************
Windows PowerShell transcript end
End time: 20210513171113
**********************
与 az 自动化相比,Start-Transcript
cmdlet 与我从我的 PC 工作站运行的工作副本的版本相同。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。