troubleshooting Question

Powershell scripting issue PS-Remoting

Avatar of ITguy565
ITguy565Flag for United States of America asked on
Scripting LanguagesShell ScriptingPowershell
3 Comments1 Solution135 ViewsLast Modified:
Experts,

What am I missing :

if I run the following , I am able to get the output I am looking for..

 enter-pssession -computername Computername
 $diskinfo = [System.IO.DriveInfo]::GetDrives()|select Name, AvailableFreeSpace, TotalSize
            $diskinfo |add-member -MemberType NoteProperty -Name PercentFree -value $null
            $diskinfo |add-member -MemberType NoteProperty -name ComputerName -value $ENV:Computername

            $diskinfo | ForEach-Object { 
                [float]$_.AvailableFreeSpace = $($_.AvailableFreeSpace/1GB)
                [float]$_.Totalsize = $($_.totalsize/1GB)
                [float]$_.PercentFree = (($($_.AvailableFreeSpace) / $($_.TotalSize)) * 100)

                 }




If I run :


$s = new-pssession -ComputerName Computername -name DiskInfo

$scriptblock = {$diskinfo = [System.IO.DriveInfo]::GetDrives()|select Name, AvailableFreeSpace, TotalSize
            $diskinfo |add-member -MemberType NoteProperty -Name PercentFree -value $null
            $diskinfo |add-member -MemberType NoteProperty -name ComputerName -value $ENV:Computername

            $diskinfo | ForEach-Object { 
                [float]$_.AvailableFreeSpace = $($_.AvailableFreeSpace/1GB)
                [float]$_.Totalsize = $($_.totalsize/1GB)
                [float]$_.PercentFree = (($($_.AvailableFreeSpace) / $($_.TotalSize)) * 100)

                 }
 }

 invoke-command -Session $s -ScriptBlock $scriptblock

 import-pssession -session $s


I get a lightshow..


What I am attempting to do is the following :


The script will be run from Computer1 and collect information for several other computers

The information will then be stored on computer1 and exported to CSV.

Can someone please show me where I went wrong with this : I am sure I am missing something simple

Thanks,
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros