Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
I am running a remote session (Enter-PSSession) and would like to save the screen output (or Out-File) locally.
While in a remote session, it would only save the file on the remote computer:
[Win5]: PS C:\> Get-NaAggr | Out-File c:\aggr.txt
I'm looking for a way to save the remote session locally, without actually going to the remote computer, is that possible?
BTW, Start-Transcript doesn't work remotely
Cheers
Joel
Solved! See The Solution
Hello Joel.
You can use the Invoke-Command cmdlet and pass the scripts inside scriptblock and put the extracted value in a variable and perform operations on them.
PS C:\Windows\system32> $a = Invoke-Command -ComputerName scvmm2012sp1 -ScriptBlock { Get-WmiObject win32_computersystem }
PS C:\Windows\system32> $a
Domain : SaRC.com
Manufacturer : Microsoft Corporation
Model : Virtual Machine
Name : SCVMM2012SP1
PrimaryOwnerName : Windows User
TotalPhysicalMemory : 4294496256
PSComputerName : scvmm2012sp1
So in Your Case, it should look like.
PS C:\Windows\system32> $a = Invoke-Command -ComputerName Win5 -ScriptBlock { Get-NaAggr }
PS C:\Windows\system32> $a | Out-File c:\aggr.txt
Hello Joel.
You can use the Invoke-Command cmdlet and pass the scripts inside scriptblock and put the extracted value in a variable and perform operations on them.
PS C:\Windows\system32> $a = Invoke-Command -ComputerName scvmm2012sp1 -ScriptBlock { Get-WmiObject win32_computersystem }
PS C:\Windows\system32> $a
Domain : SaRC.com
Manufacturer : Microsoft Corporation
Model : Virtual Machine
Name : SCVMM2012SP1
PrimaryOwnerName : Windows User
TotalPhysicalMemory : 4294496256
PSComputerName : scvmm2012sp1
So in Your Case, it should look like.
PS C:\Windows\system32> $a = Invoke-Command -ComputerName Win5 -ScriptBlock { Get-NaAggr }
PS C:\Windows\system32> $a | Out-File c:\aggr.txt
Cool
What if I need to run this on the remote machine and save a report locally:
Import-Module DataOntap
$filer = Read-Host "This will show volumes more than 85% full. Please enter the filer name"
$user = "Enter the username"
Connect-NaController $filer -Credential $user
Get-NaVol | select name,PercentageUsed,Aggregate,SnapshotPercentReserved,SpaceReserveEnabled,MirrorStatus | where { $_.PercentageUsed -gt 85 }
Hello, Here's a function i wrote which can be used to attain this information.
Here im calling the local variables in a remote powershell session using "$using" which is a new feature in PowerShell v3
function Get-VolInfo {
$filer = Read-Host "This will show volumes more than 85% full. Please enter the filer name"
$user = Get-Credential
$a = Invoke-Command -ComputerName Win5 -ScriptBlock {
Import-Module DataOntap
$new = Connect-NaController $using:filer -Credential $using:user
Get-NaVol | select name,PercentageUsed,Aggregate,SnapshotPercentReserved,SpaceReserveEnabled,MirrorStatus | where { $_.PercentageUsed -gt 85 }
}
return $a
}
Just copy paste the above function to your powershell window and invoke the function by calling it as below, it should give you the required information.
Get-VolInfo
cool
Is there a way to save this function so that every time I run Get-VolInfo it will call it?
- what does the 'return' do?
- can you put it in a table (not list)?
Thanks
Hello Joel,
You can copy paste the function and save it in a ps1 file, and add it to your powershell profile, so that everytime you open up powershell it autoloads the function.
Check this link http://windowsitpro.com/powershell/save-your-powershell-code-profile-and-script-files
Worked!
I saved it as .psm1 file and then I just need to import that:
Import-Module c:\scripts\getvolinfo.psm1
We also had to Enable-PSRemoting
- what does the 'return' do?
- can you put it in a table (not list)?
Hello,
To Change the view from Lists to Tables use ft (format-table)
Just put an ft * to the end and you should see the result in tabular format.
where { $_.PercentageUsed -gt 85 } | ft *
Also return return's the output from function.