I am getting an error using a New-PSDrive inside a universal powershell grid.
The specified drive root “\servername01.domain.local\c$” either does not exist, or it is not a folder.
it works fine if I just run it as a power shell function and does the right thing but inside the grid and trying to render in IIS, I get this error.
any ideas or thoughts?
New-UDGrid -Title "Service Status" -AutoRefresh -RefreshInterval 120 -Endpoint{
$serviceStatObjs = @()
function getservicestats {
param($servername,
$serviceName,
$Cred
)
# Write-Output "Hello"
New-PSDrive -Name tempDriveName –PSProvider FileSystem –Root "\\$servername\c$" -Credential $Cred
$serviceInfo = Get-Service -ComputerName $servername -Name $serviceName -ErrorAction SilentlyContinue | Select-Object Displayname,Name,Status
Remove-PSDrive -Name tempDriveName
# Write-Output "ServiceInfo = " + $serviceInfo
if($serviceInfo.Status -eq 'Running'){$stat = "Running"}
Elseif($serviceInfo.Status -eq "stopped"){$stat = "Stopped"}
$serviceObj = [PSCustomObject]@{
ServerName = $servername
ServiceDisplayName = $serviceInfo.Displayname
Status = $stat
}
$serviceObj
}
$data = @(
[pscustomobject]@{Server="servername01.domain.local";ServiceName="Onlife.MessageService";login=$Creds}
)
foreach($service in $data){
$serviceStatObjs += getservicestats $service.Server $service.ServiceName $service.login
}
#output as usable data
$serviceStatObjs | Out-UDGridData
}