我的 Powershell 脚本没有写入我指定的文本文件,我不知道为什么。该脚本当前登录到远程服务器,据我所知,它正在正确执行 powershell 作业以收集数据。我最初试图注销远程会话然后写入数据,但变量$Data
没有保留数据。
Add-PSSnapin vmware.vimautomation.core #required for vm-cmdlets
$User = [Environment]::UserName
$Workstation = [Environment]::MachineName
$Log = "\\folder\user$\name\CompasFound.txt"
$Search_Dir = Get-Content -Path C:\Users\$User\Documents\WheresMyCompass.txt
$Servers = Get-Content -Path C:\Users\$User\Documents\WheresMyWorkStation.txt
#Enter-PSSession -Computer vmname
Connect-VIServer -Server 192.168.x.x -User "user" -Pass "pass"
Function CompassFinder #Finding Compass file(s) function
{
Start-Job -Name CompFind -ScriptBlock{
$Data = Get-Childitem -Path $Search_Dir -Recurse *.doc;
#Exit-PSSession; #Breaking remote session
$Data | Format-Table -AutoSize | Add-Content $Log #Writing data
}
}
Function GenLogFinder #Finding GeneralLog file function
{
Start-Job -Name LogFind -ScriptBlock{
$GLogData = Get-Childitem -Path $Search_Dir -Recurse -Include GeneralLog.txt;
#Exit-PSSession; #Breaking remote session
$GLogData = Format-Table -AutoSize | Add-Content $Log -append; #Writing data
}
}
CompassFinder;
GenLogFinder;