This topic contains 4 replies, has 2 voices, and was last updated by
July 24, 2018 at 2:01 pm #105070
I'm a powershell-newb. My goal is to rename pc's and afterwards release the ip address and shut them down... remotely.
I'm guessing my problem is understanding exactly how enter-pssession works. I was hoping all commands applied to that session while connected. The rename part works perfectly. After the rename, my goal is to physically move the computer to a different subnet, so I would like to release the ip and shut them down. I have no clue how to script, I'm just now learning the basics of powershell and so far this is what I have:
$OldComputername= Read-Host 'Enter Old PC Name' $NewComputerName= Read-Host 'Enter New PC Name' Enter-PSSession -ComputerName $OldComputername -Credential domain\user Rename-Computer -ComputerName $OldComputername -NewName $NewComputerName -DomainCredential domain\user | ...
I've tried cmd commands like ipconfig /release followed by shutdown -s -t 10, but these commands only applied to my local session. I've even tried to call upon a .bat file saved locally on the pc that I know could also perform the release/shutdown function I need, but I can't figure out how to start the .bat file using enter-possession.
Any tips, criticisms, ideas are all welcome.
Thanks for reading...
July 24, 2018 at 2:05 pm #105071KeymasterPoints: 1,619Rank: Community Hero
Windows already sends a DHCP-Release when it shuts down; most DHCP servers will still "save" the old address and re-issue it on reboot. But that's up to the server; the client can't force the DHCP server to actually release the address. So there shouldn't be a need to manually release the address.
I'm guessing my problem is understanding exactly how enter-pssession works. I was hoping all commands applied to that session while connected.
They do. But renaming a computer will close the connection because the computer's name changed. Traffic can't be routed to the old name any longer, so you'd need to reconnect using the old name. Remoting also relies on a name lookup in AD to authenticate, so once you rename the computer the prior authorization is gone and, again, you have to reconnect. If you manually ran these commands, you'd probably see the disconnect happening.
But there's no need for a PSSession. Rename-Computer (and Restart-Computer, and Stop-Computer) all handle remote connections internally as it is. That's what the -ComputerName parameter is doing.
July 24, 2018 at 6:07 pm #105082
I very much appreciate the help and do hope you have more input. I wanted to double check something you said regarding releasing the ip address. You stated "the client can't force the DHCP server to actually release the address". Are you referring to just powershell? I was under the impression this is exactly what the command prompt "ipconfig /release" does. I'm trying to swap out a call center's worth of pc's. In the past, we have always had to release the ip's or we run out of them on the subnet we work from. With that said that would mean the /release does in fact tell the server to free up the ip address for the next machine. ...Now i could totally be misunderstanding what is going on behind the scenes, but this is how i have "had" to do it in the past, for years.
So with that said i'm still trying to find a way to have 3 things happen: a pc rename, an ip release, and a shutdown. Due to the authentication/disconnects with both the rename and the ipconfig /release, I need to figure out a way to get all of these commands to run on the machine after i have been disconnected. I need to give it a list of commands it can continue to follow after i lose authentication/connection.
I'm being a little redundant there, sorry about that. Anyways, i hope you see what i'm trying to do. If you have anymore insight or corrections to my line of thinking, i'm very much all ears and again, thank you for the help.
July 24, 2018 at 7:09 pm #105107KeymasterPoints: 1,619Rank: Community Hero
So, first, a client can't force a server to do anything. It can just ask. Many DHCP implementations these days won't delete a record automatically, although they'll make it available for reassignment. You're kind of operating from 1990s assumptions.
Second, there's no need to release an IP unless your working from 1990s superstitions or have a deeply flawed infrastructure. Let the computers do their jobs at managing IP. They're better at it than us monkeys these days.
Third, you can't do what your asking. Full stop.
You could redo this in Workflow in PowerShell, ship the entire workflow to the remote machine, and let it run it. Workflow is designed to resume after a restart.
Or why not just add -Restart to Rename-Computer and let that command take care of it? Again, explicitly releasing the IP is just creating unnecessary work for the infrastructure. I see lots of superstitious admins do it, but it's 2018!
Last resort, issue the rename, disconnect, and reconnect to the new name to do the rest of what you're doing. That may get a little complex because the renamed computer is really gonna want to restart first. But Remoting authentication is based in part on the computer name, which is why people just let Rename-Computer do it's job instead of trying to micro-manage the process themselves.
Easy enough to let Rename also restart, issue. start-sleep for a few minutes, and the reconnect to the new computer name.
July 25, 2018 at 1:58 pm #105196
Don thank you very much for the insight and thank you for sharing your knowledge via your book. Its been a while since i tried to learn something new and i find im able to think further outside the box when doing my job now.
Sincerely, thank you.
The topic ‘ip release/shutdown’ is closed to new replies.