I need some help. I cant’t find what’s wrong with my PowerShell script.
The goal is quite simple. I have to find (.*pst)-files on the users profile on domain computers in the network.
Location to search is “C:\Users\”.
List of the PC names where exported to listcomputer.txt.
The trouble is the script run with no errors and no message at all.
$computers = Get-Content c:\temp\listcomputer.txt
$filePath = "C:\Users\"
foreach($computer in $computers)
{
if(Test-Connection -ComputerName $computer -Quiet)
{
Invoke-Command -ComputerName $computer -ScriptBlock
{Get-ChildItem -Path $filePath -Recurse -Include '*.pst, *.ost'} }}
First of all I’ve to check connectivity to hosts by Test-Connection cmdlet.
Separately each of the command run successfully. I've tried it.
For example: Test-Connection -ComputerName $computer
runs with “true” result and it’s OK.
Also
Invoke-Command -ComputerName $computer -ScriptBlock {Get-ChildItem -Path $filePath -Recurse -Include '*.pst'}
The result is displayed data with information about files were find in folders.
But all together run with no visible result in the PowerShell console
console view result
Regards!
$a = Get-RemoteAccessConnectionStatisticsSummary return $aat the end of your ScriptBlock and let me know the result.$filePathis unknown in the scriptblock. TryGet-ChildItem -Path $using:filePath ..or hardcode the'C:\Users'there. You can also define it as param(..) in the scriptblock and useArgumentListin Invoke-Command