Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define the target machine and path
- $remoteComputer = "RemoteMachineName" # Replace with the remote machine's name or IP
- $pathToCheck = "C:\Path\To\Check" # Replace with the path to check
- # Function to check if a path exists
- function Check-PathExists {
- param (
- [string]$computerName,
- [string]$path
- )
- Invoke-Command -ComputerName $computerName -ScriptBlock {
- param ($remotePath)
- if (Test-Path $remotePath) {
- return "Path exists: $remotePath"
- } else {
- return "Path does not exist: $remotePath"
- }
- } -ArgumentList $path
- }
- # Call the function and display the result
- $result = Check-PathExists -computerName $remoteComputer -path $pathToCheck
- Write-Host $result -ForegroundColor Green
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement