I have a simple PowerShell that accepts a file as a parameter that contains Server-Name, Service-Name and Timeout specified in seconds and the powershell stops/starts the services based on the command. I have 10 servers where application related services are configured and I'm using Workload automation capabilities to run this code on any server with the same parameter file and powershell present on all 10 servers.

All of this works fine with server names hardcoded in the param file. We have n+2 Infrastructure, and I created DNS Aliases for all the 10 servers to make Active-Standby switchover little easy. Now the problem comes with stop/start script. Ex: If the script gets invoked in Server 7, all the services will be shutdown except for the ones in Server 7 and I get below error:

Get-Service : Cannot find any service with service name 'Application-Server7'.
At line:1 char:1
+ Get-Service -ComputerName app7test -Name Application-Server7
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Application-Server7:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

I just tested one-liner command using PowerShell ISE on the computer "appnewora79 "and below are the results.

This works fine:

Get-Service -ComputerName appnewora79 -Name Application-Server7
Status Name DisplayName

------ ---- -----------

Stopped Application-Ser... Application-Server7

This fails:

Get-Service -ComputerName app7test -Name Application-Server7
Get-Service : Cannot find any service with service name 'Application-Server7'.
At line:1 char:1
+ Get-Service -ComputerName app7test -Name Application-Server7
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Application-Server7:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

Any suggestions to overcome this, please?

I don't see what I do wrong :(
I habe a directory structure as example this one

[0] ON1 > gci -Recurse


Verzeichnis: C:\Temp\ON1


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 17.07.2018 21:21 dir1
da---- 17.07.2018 21:21 dir3
d----- 17.07.2018 12:51 dir4
-a---- 28.02.2018 19:56 5191 _mg_2499.on1
-a---- 28.02.2018 19:56 5191 _mg_2499.xmp
-a---- 28.02.2018 19:05 5191 _mg_2500.on1
-a---- 28.02.2018 19:05 5191 _mg_2500.xmp
-a---- 28.02.2018 19:43 5191 _mg_2501.on1
-a---- 28.02.2018 19:43 5191 _mg_2501.xmp
-a---- 28.02.2018 18:52 5191 _mg_2502.xmp
-a---- 28.02.2018 19:06 5191 _mg_2503.xmp
-a---- 28.02.2018 19:22 5193 _mg_2504.xmp


Verzeichnis: C:\Temp\ON1\dir1


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28.02.2018 19:56 5191 _mg_2499.on1
-a---- 28.02.2018 19:56 5191 _mg_2499.xmp
-a---- 28.02.2018 19:05 5191 _mg_2500.on1
-a---- 28.02.2018 19:05 5191 _mg_2500.xmp
-a---- 28.02.2018 19:43 5191 _mg_2501.on1
-a---- 28.02.2018 19:43 5191 _mg_2501.xmp
-a---- 28.02.2018 18:52 5191 _mg_2502.xmp
-a---- 28.02.2018 19:06 5191 _mg_2503.xmp
-a---- 28.02.2018 19:22 5193 _mg_2504.xmp


Verzeichnis: C:\Temp\ON1\dir3


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28.02.2018 19:56 5191 _mg_2499.on1
-a---- 28.02.2018 19:56 5191 _mg_2499.xmp
-a---- 28.02.2018 19:05 5191 _mg_2500.on1
-a---- 28.02.2018 19:05 5191 _mg_2500.xmp
-a---- 28.02.2018 19:43 5191 _mg_2501.on1
-a---- 28.02.2018 19:43 5191 _mg_2501.xmp
-a---- 28.02.2018 18:52 5191 _mg_2502.xmp
-a---- 28.02.2018 19:06 5191 _mg_2503.xmp
-a---- 28.02.2018 19:22 5193 _mg_2504.xmp


Verzeichnis: C:\Temp\ON1\dir4


Mode LastWriteTime Length Name
---- ------------- ------ ----
da---- 17.07.2018 21:22 dir2


Verzeichnis: C:\Temp\ON1\dir4\dir2


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28.02.2018 19:56 5191 _mg_2499.on1
-a---- 28.02.2018 19:56 5191 _mg_2499.xmp
-a---- 28.02.2018 19:05 5191 _mg_2500.on1
-a---- 28.02.2018 19:05 5191 _mg_2500.xmp
-a---- 28.02.2018 19:43 5191 _mg_2501.on1
-a---- 28.02.2018 19:43 5191 _mg_2501.xmp
-a---- 28.02.2018 19:56 5191 _mg_2502.on1
-a---- 28.02.2018 18:52 5191 _mg_2502.xmp
-a---- 28.02.2018 19:06 5191 _mg_2503.xmp
-a---- 28.02.2018 19:22 5193 _mg_2504.xmp
-a---- 28.02.2018 19:11 5191 _mg_2505.xmp
-a---- 28.02.2018 19:11 5167 _mg_2506.xmp

Now I want to find in all directories files with same name but different extension.

_mg_2499.xmp exist and _mg_2499.on1 exist - do nothing

_mg_2503.xmp exist but _mg_2503.on1 don't exist -> give me response Path\Filename and create file


I was trying with this code but something is wring here :(

$DirList = @()
$ON1FileList = @()
$XMPFileList = @()

# Liste der verzeichnisse erstellen
$DirList = $(Get-ChildItem -Recurse -Directory).FullName

foreach ($Dir in $DirList) {
# Liste der XMP Dateien erstellen
$XMPFileList = Get-ChildItem -Filter *.xmp

# Liste der ON1 Dateien erstellen
$ON1FileList = Get-ChildItem -Filter *.on1

$FileList = Compare-Object $XMPFileList $ON1FileList -IncludeEqual -Property BaseName | ? {$_.SideIndicator -eq "<="}

foreach ($File in $FileList) {
$FileToCreate = $Dir + "\" + $File.BaseName + ".on1"
new-Item $FileToCreate -WhatIf
}
}

Post has attachment

Post has attachment
#Azure Cloud Shell on Linux Containers -
#PowerShell
✔ More Speed
✔ No longer a Windows Experience
✔ Runs on PowerShell Core 6.x
✔ pwsh NOT PowerShell.exe
✔ Case Sensitivity
✔ Storing your work
✔ Beware of Aliases
✔ Azure Cloud Shell from Visual Studio Code

Youtube - https://youtu.be/FjOifhvRwgU

Post has attachment
Happy to announce that a book project I've been working on has finally reached the public stage. Ever wanted to attend a deep PowerShell-centric conference? Well, think of this as a conference in a book. Deep technical content on a number of PowerShell related topics. Plus, all sales go to fund IT-based scholarships. You can learn more at https://leanpub.com/powershell-conference-book. #PSConfBook
Photo

Post has attachment

Post has shared content

Post has attachment
Just published a new version of the #PowerShell Practice Primer to fix a number of spelling mistakes. https://leanpub.com/psprimer/

Post has attachment
Com o software Bruno Espião vocês pais consegue,
monitorar o whatsapp de seus filhos no celular...

Acesse: https://brunoespiao.com.br/espiao-de-whatsapp
E veja como ver as mensagens do whatsapp de seus filhos...

Post has attachment
Wait while more posts are being loaded