Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Execute script on Multiple servers using Powershell

$
0
0

Hi,

I am SQL server DBA and would like to use powershell to execute the below script to monitor the space in multiple servers.

I have saved the server names in the file called "ServerList.txt" 

########*****Script**********#######

DEL "C:\DB_Checkouts\Diskspace\Output.CSV"

COPY "C:\DB_Checkouts\Diskspace\MasterFile.CSV" "C:\DB_Checkouts\Diskspace\Output.CSV"

$ServerListFile = "C:\DB_Checkouts\Diskspace\ServerList.txt" 
$ServerList = Get-Content $ServerListFile 
$Result = @()
$user= whoami 
$date = (get-Date).tostring()
ForEach($computername in $ServerList)
{
gwmi Win32_LogicalDisk -Computername $computername -Filter "Drivetype=3" |select Computername, Name, Size, FreeSpace,BlockSize | % {$_.Computername=($env:COMPUTERNAME);$_.Size=($_.Size/1GB);$_.FreeSpace=($_.FreeSpace/1GB);$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_} | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append -Encoding ascii -FilePath "C:\DB_Checkouts\Diskspace\Output.CSV"
}

When I am executing the above query, I'm getting below error. Kindly check and share your thoughts to fix the issue.

 

####************Error*************####

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:12 char:5
+ gwmi <<<<  Win32_LogicalDisk -Computername $computername -Filter "Drivetype=3" |select Computername, Name, Size, FreeSpace,BlockSize | % {$_.Computername=($env:COMPUTERNAME);$_.Size
=($_.Size/1GB);$_.FreeSpace=($_.FreeSpace/1GB);$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_} | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | Select-Object -Skip 1 | Out-File -Ap
pend -Encoding ascii -FilePath "C:\DB_Checkouts\Diskspace\Output.CSV"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>