Advertisement
Kalidor_Vorlich

2

Dec 20th, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Define the target machine and path
  2. $remoteComputer = "RemoteMachineName" # Replace with the remote machine's name or IP
  3. $pathToCheck = "C:\Path\To\Check" # Replace with the path to check
  4.  
  5. # Function to check if a path exists
  6. function Check-PathExists {
  7. param (
  8. [string]$computerName,
  9. [string]$path
  10. )
  11.  
  12. Invoke-Command -ComputerName $computerName -ScriptBlock {
  13. param ($remotePath)
  14. if (Test-Path $remotePath) {
  15. return "Path exists: $remotePath"
  16. } else {
  17. return "Path does not exist: $remotePath"
  18. }
  19. } -ArgumentList $path
  20. }
  21.  
  22. # Call the function and display the result
  23. $result = Check-PathExists -computerName $remoteComputer -path $pathToCheck
  24. Write-Host $result -ForegroundColor Green
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement