Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Out-File Question

$
0
0

I have this code that works on my local Windows 7 machine.

 

(get-wmiobject win32_operatingsystem).converttodatetime((get-wmiobject win32_operatingsystem).installdate)

 

but both sets of code below fail.  Both create the .csv file but nothing gets written to it.   Why?  

 

 

 

$PCs = Get-Content "c:\temp\tmp\machines.txt"
$OSDate = (get-wmiobject win32_operatingsystem).converttodatetime((get-wmiobject win32_operatingsystem).installdate)

Foreach ($machines in $PCs) {
    $OSDate | Out-File "c:\temp\tmp\OSInstallDate.csv"
    }

 

---------------------------------------------------------------------------------------------------

 

 

 

 

$PCs = Get-Content "c:\temp\tmp\machines.txt"


Foreach ($machines in $PCs) {
    (get-wmiobject win32_operatingsystem).converttodatetime((get-wmiobject win32_operatingsystem).installdate) | Out-File "c:\temp\tmp\OSInstallDate.csv"
    }

 

 

 


Viewing all articles
Browse latest Browse all 8411

Trending Articles