Fun with PowerShell: where did I put that file?
Waaaaaaay back in mid-March of this year, I made a PowerShell script file that I had left on a server somewhere. Now, this is admittedly a bad practice because you should have it stored somewhere that you know of and it needs to be in some sort of source control. I, while living dangerously, thought nothing of it as I was just simply scripting away as fast as my hands could type. Come Monday morning, and I’m scratching my head as to where I left the file. Hmmm… okay. Sixteen servers – where is that file? Ah.. PowerShell – do my bidding. A few minutes later and I come up with this gem.
$servers = @('srv01','srv02','srv03','srv04','srv05','srv06','srv07','srv08', 'srv09','srv10','srv11','srv12','srv13','srv14','srv15','srv16') $servers | %{ Invoke-Command -ComputerName $_ -scriptblock { dir C:\Users\ian.paullin\Desktop\*.ps1 }}
You could probably make this into a one-liner or a parameterized script, but for my usage, it was perfect as I wasn’t even sure of the PowerShell script I was looking for. All I knew was I left it on the desktop.