My “out-file” stuff is inside the invoke-command script block and therefore is executed from the remote computer. The user THERE does not have Write access to the folder
So, I moved the out-file stuff outside of the script block
invoke-command -computername $hostname -script {
$SettingList = Get-WmiObject -Namespace root\HP\InstrumentedBIOS -Class HP_BIOSEnumeration
#Return the current and available values for a specific setting
$Settings = ($SettingList | Where-Object Name -eq "Secure Boot")
$settings
pause
}
$settings | out-file -filepath \\cenfiler\mis$\SecureBoot\$hostname.txt -append
Now, it writes a blank file onto the share. I confirmed that $settings has data before the “pause”, but it doesn’t make it out of Invoke-Command
First, when formatting your code, don’t quote it, use the </> button and paste it between the backticks. If you can’t see the </> button in the toolbar, it will be under the gear icon.
As to your problem, it sounds like you’re running into the second hop problem. This is summarised as:
You are logged in to ServerA.
From ServerA, you start a remote PowerShell session to connect to ServerB.
A command you run on ServerB via your PowerShell Remoting session attempts to access a resource on ServerC.
Access to the resource on ServerC is denied, because the credentials you used to create the PowerShell Remoting session aren’t passed from ServerB to ServerC.
You can understand more about the problem and possible solutions here:
$Results = Invoke-Command -ComputerName $hostname -script {
$SettingList = Get-WmiObject -Namespace root\HP\InstrumentedBIOS -Class HP_BIOSEnumeration
#Return the current and available values for a specific setting
$Settings = ($SettingList | Where-Object Name -EQ "Secure Boot")
Write-Output $settings
Pause
}
$Results | Out-File -FilePath \\cenfiler\mis$\SecureBoot\$hostname.txt -Append
Other comments:
Get-CimInstance is generally preferred to Get-WmiObject.
I would suggest looking at the help for Get-CimInstance. That command can be run against a remote computer instead of using Invoke-Command. Something like this would be much cleaner: