Powershell mystery
I had never tried this previously and hence why I only just noticed it. I am far from completely competent with powershell yet, still picking up lot's.
Scenario:-
I have a vmware network at work, x2 2003 servers, both on same subnet/network.
The server I am running this script from isn't assigned to any domain yet and just sit's in a workgroup. The other server is a AD DC 2003.
The script:-
The pclist contains the computer name of both servers.
I ran the script expecting it not to work on the AD DC 2003 server, but it did. My thoughts were:-
a) The script surely shouldn't be able to be run this remove-item cmdlet on a remote server, especially when there are no matching windows user authentication to perform this task.
b) I havent tried this on other platforms yet but I am completely clueless.
Anyone that can explain?
Cheers,
Scenario:-
I have a vmware network at work, x2 2003 servers, both on same subnet/network.
The server I am running this script from isn't assigned to any domain yet and just sit's in a workgroup. The other server is a AD DC 2003.
The script:-
$a = Get-Content "C:\Scripts\pclist.txt" foreach ($i in $a) { remove-item \\$i\C$\Scripts\remove -recurse }
The pclist contains the computer name of both servers.
I ran the script expecting it not to work on the AD DC 2003 server, but it did. My thoughts were:-
a) The script surely shouldn't be able to be run this remove-item cmdlet on a remote server, especially when there are no matching windows user authentication to perform this task.
b) I havent tried this on other platforms yet but I am completely clueless.
Anyone that can explain?
Cheers,
DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
Comments
-
HeroPsycho Inactive Imported Users Posts: 1,940Are you logged in with a local user account that has a mirrored local user account on the remote machines?Good luck to all!
-
Pash Member Posts: 1,600 ■■■■■□□□□□HeroPsycho wrote:Are you logged in with a local user account that has a mirrored local user account on the remote machines?
Hi Hero!
No that wasn't the case. I thought of that at the start.
BUT I do know why it worked. Windows had cached sharepath credentials for \\remotepcname\c$ previously, hence why I was allowed to connect to an administrative share and remove a folder.
Silly me.
Cheers,DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Pash Member Posts: 1,600 ■■■■■□□□□□
#file required in location for Get-Content $a = Get-Content 'C:\Scripts\pclist.txt' $b = "Scripts\remove" $c = "c$" foreach ($i in $a) { if (Test-Path \\$i\$c\$b) { remove-item \\$i\$c\$b -recurse -Force -confirm "$b successfuly removed from: $i" } else { "$b does not exist on $i" } }
I modified this script to make it useful to remove folders or files on multiple pc's with a confirmation required before each removal. I don't know if anyone else will have use for it but please go ahead....DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Pash Member Posts: 1,600 ■■■■■□□□□□Please elaborate dude, I mean I still wan't to display to console window if the if statement isnt met it has to meet something right?DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
-
HeroPsycho Inactive Imported Users Posts: 1,940I'm confused what you're asking (and if you're asking yourself a question....)Good luck to all!
-
royal Member Posts: 3,352 ■■■■□□□□□□HeroPsycho wrote: »I'm confused what you're asking (and if you're asking yourself a question....)
I believe he was replying to a post I made earlier in which I was wrong since I didn't scroll through all the code and realized that so I deleted my post.“For success, attitude is equally as important as ability.” - Harry F. Banks -
Pash Member Posts: 1,600 ■■■■■□□□□□I believe he was replying to a post I made earlier in which I was wrong since I didn't scroll through all the code and realized that so I deleted my post.
This would be itDevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.