Trying to Run below script to get mapped Drive info from remote workstations/Desktops. This script will get the current user's mapped drive info and put it in the CSV file locally and import the data in Network File.
$time=get-date
$explorer = Get-WmiObject -ComputerName $env:COMPUTERNAME -Class win32_process | ?{$_.name -eq "explorer.exe"}
$LocalOutputfile="c:\temp\Local_MappedDrvReport.csv"
$RemoteOutputfile="\\Networkserver\sharedfolder\MappedDrivers.csv"
if($explorer){
$Hive = [long]$HIVE_HKU = 2147483651
$sid = ($explorer.GetOwnerSid()).sid
$owner = $explorer.GetOwner()
$Person = "$($owner.Domain)\$($owner.user)"
}
$Report1=Get-WmiObject win32_mappedlogicaldisk -ComputerName $env:COMPUTERNAME
$Report1|select-object @{n='Date';e={$time}},@{n='UserName';e={$Person}},deviceid,providername,pscomputername|Export-Csv -Path $LocalOutputfile
Import-Csv $LocalOutputfile |Export-Csv -Path $RemoteOutputfile -NoTypeInformation -Append
$file1=test-path $RemoteOutputfile
if ($file1 -eq $true){[System.Environment]::Exit(0)}
else{[System.Environment]::Exit(1)}
Problem is:
Locally on a workstation, this script is running successfully but if its run by using SCCM then it creates an empty CSV file on the local path so no data gets imported into the network file.
i am using SCCM 1906> Application Management>Packge>program> created new program to run ps script
Command> Powershell.exe -Executionpolicy bypass -File filename.ps1
Run Mode > Run With Admin rights
Also tried with specific User/Admin Account but the output file is still empty
Default execution policy in Client setting set as "AllSigned"
I checked by changing it to Bypass but that's also not helping
Please help to find the whats wrong in Script or in Setting?