Thanks Martin. I was really close
Reply To: Regex question
Reply To: Copying file using CIM_logical file in PS
I don't believe you can. Your UNC path would look more like this
$newfile = "\\\\Server\\C$\\$($file.FileName).$($file.Extension)"
I think.
if you mapped a drive to the remote machine it should work
Managing .mof files. How do you avoid making multiple .mofs for the same node?
I have a question about the in-between place at authoring and staging of .mof files in a pull scenario. Just to review the workflow as I understand it:
- A configuration builds .mof files, one for each node.
- The .mof files must be renamed according to a machine's assigned GUID. (I've also read it's possible for many machines to share a GUID as well)
- .checksums are generated for each new .mof file and these file pairs are placed in the appropriate directory of the pull server.
- Sometime within the next interval (30 minutes default) pull-enabled DSC machines will check in and fetch their .mof file and process it.
The LCM for each DSC node will only parse one .mof file, the one it fetched because that filename matched its assigned GUID. So it follows that if I write two or three or more configs that create .mof files for the same node then we have a bit of a situation. Either we need to get all these merged together, or the powershell configurations need to be melded into one by compositing, but I haven't read anywhere where someone explicitly says this. This leads me to wonder whether I've missed something, like for example there is a .mof merger and it's part of some utility that "publishes" your .mof files.
If the workflow is as I describe it then all configs we write for publication to one DSC server probably should be managed in one giant set of composite powershell configurations, otherwise you risk a situation where running more that one script produces multiple .mof files for the same machine. Either that, or you must logically segregate all your machines into groups that are managed by separate configs, but this leaves out the possibility of managing all of them with some uniform basic parameters which I imagine most organizations might want.
At this time, the documentation describing the process of publishing and managing .mof files seems a bit thin. Can anyone recommend some good blog posts on the subject or a publishing utility of the sort I just described?
Reply To: Copying file using CIM_logical file in PS
Sadly, this didn't work , any other suggestion?
guidance on how to remotely run powershell function, please
I am working on automating WSUS updates.
I have a simple, basic script here that I can use: https://gist.github.com/jacobludriks/9ca9ce61de251a5476f1
It's also a function, which is good
My desire is to run the function remotely upon an array of servers, like so:
foreach in $servers array, e.g. foreach ($server in $servers) {
** properly connect to server
run the wsus update function
sleep/wait a few minutes
next server
Is this a good way to do this and what code do I need to ** properly connect to the server??
What is the proper code for server connection such that I can use $server and not the actual server name??
Thank you, Tom
Nested Groups – User Properties
Hello and thank you for your anticipated help with this.
Pretty new at Powershell because I was good at the old ways.
Doing my best to stop going back to the old, familiar out of date ways so here goes.
Below is a script that I've put together from things found on the interwebs.
It walks through a group and subgroups for members and displays as required.
It's working as designed but new requirements from the client have come forth
req 1: don't show disabled users
req 2: don't show accounts with no defined expiration date
When I attempt to have it skip disabled users with (below) I get an error.
`Get-ADUser -filter {enabled -eq $true} -Prop Description…….
Any help with this as well as not displaying the hundreds of users accounts that don't have the account expiry set would be greatly appreciated.
function Get-ADNestedGroupMembers {
[cmdletbinding()]
param (
[String] $GroupName
)
import-module activedirectory
$Members = Get-ADGroupMember -Identity $GroupName
$members | % {
if($_.ObjectClass -eq "group") {
Get-ADNestedGroupMembers -GroupName $_.distinguishedName
} else {
return $_.distinguishedname
}
}
}
import-module activedirectory
Get-ADNestedGroupMembers -groupname "group name here" |
`Get-ADUser -Prop Description,samAccountName,AccountExpirationDate, mail, LastLogoff, lastLogonTimestamp, company |
`Select-Object Name,samAccountName,AccountExpirationDate, mail, LastLogoff, @{N='LastLogonTimestamp'; E={[DateTime]::FromFileTime($_.LastLogonTimestamp)}}, company |
`Sort-Object AccountExpirationDate -descending |
#`Format-Table -property * -AutoSize |
`ConvertTo-HTML | Out-File C:\Temp\working\AccountExpiry.htm
Reply To: Read from File – Query AD
Thank you Don.
Following your lead I was able to get the script working (albeit painful but that's learning)
Injecting multiple lines of text into a file
I've got a config file that I'm trying to inject some new config data into. I've been trying to get it going using this, but I can't get the content of the file to match more than one line at a time (isn't that what -Raw is for?)
$originalConfig = @"
mergeTools.beyondcompare2.commandLine=bc2.exe /title1="Merge From:{1}" /title2="Working File:{3}" "{5}" "{7}" /savetarget="{7}"
mergeTools.araxis.title=Araxis Merge, Araxis Ltd.
"@
$newConfig = @"
mergeTools.beyondcompare2.commandLine=bc2.exe /title1="Merge From:{1}" /title2="Working File:{3}" "{5}" "{7}" /savetarget="{7}"
mergeTools.beyondcompare3.title=Beyond Compare 3.x, Scooter Software
mergeTools.beyondcompare3.commandLine="C\:\\Program Files (x86)\\Beyond Compare 4\\BComp.exe" /title1\="{1}" /title2\="{2}" /title3\="{0}" "{5}" "{6}" "{4}" "{7}"
mergeTools.araxis.title=Araxis Merge, Araxis Ltd.
"@
$configFile = Join-Path "${Env:ProgramFiles(x86)}" "Integrity\IntegrityClient10\IntegrityClientSite.rc"
(Get-Content $configFile -Raw) -replace $originalConfig, $newConfig | Set-Content $configFile -Force
Any thoughts on what I'm missing?
Reply To: Managing .mof files. How do you avoid making multiple .mofs for the same node?
Check out Partial DSC configurations that is coming in Powershell 5.
Reply To: Injecting multiple lines of text into a file
Hi Rich,
Can you try using the .Replace method of the string instead of -replace. It's probably to do with it interpreting it as containing regex. So something like this.
(Get-Content $configFile -Raw).Replace($originalConfig, $newConfig) | Set-Content $configFile -Force
Reply To: Managing .mof files. How do you avoid making multiple .mofs for the same node?
The partial config is more for multiple department configs. once group does OS, another does the application SQL, not to mention no all companies can use Preview software (unless we like looking for work)
I find it best to think of it this way.
GPO does all the compiling of settings every 90 minutes on each and every server.
DSC, you do all the compiling of settings on the development machine then every server just runs the results.
Instead of compiling multiple mof's you just update the existing configuration script and run it again to create a new .mof There is even some good examples or composite configs that work with vmf 4.0
Reply To: Invoke-DSCPull runs twice
Are you suggesting we abandon the powershell.org DSC tools?
I agree what is free (Powershell.org DSC tools, Jenkins, Gerrit) may not have all the polish of Chef. but with out the deep pockets to run Chef at scale, the free tools are a good place to start.
Reply To: guidance on how to remotely run powershell function, please
Hi Tom,
Best thing i can recommend is to take a look at the free ebook Secrets of PowerShell remoting.
You can find it via Resources / Free E-Books on this site or directly via :
https://www.penflip.com/powershellorg/secrets-of-powershell-remoting
Reply To: Nested Groups – User Properties
Hey Mike,
What's the error you are getting? I ran the command on my DC a couple of seconds ago, and it worked okay.
Reply To: guidance on how to remotely run powershell function, please
OIC — found and downloaded.
Seems what I must do now is write a test script and practice having it run remotely on the servers, then work on the WSUS stuff.
Thank you, Tom
Uninstall Sofware using registry key
I am trying to build something to uninstall APC Powerchute Network Shutdown. I need to do a few things here:
1 – Go through AD and find the machines (Done)
(Get-ADComputer -SearchBase "OU=Servers,DC=domain=ca" -filter *).name
2 – Get the registry value (Done)
Get-RegString -Key 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\powerchute network Shutdown' -Value UninstallString
3 – Now I need to uninstall using the uninstall key but the problem is that I can't figure out how to pass all this through
Any ideas?
Here is what I have:
Get-QADComputer -Searchroot "OU=Servers,DC=DOMAIN,DC=ca"| ForEach-Object {
[PSCustomObject] @{
Servername = $_.name
online = Test-Connection $_.name -Count 1 -Quiet
}
} | Export-Csv -Path c:\Results.csv -NoTypeInformation
# selecting only computers online | where {$_.name online}
| Foreach-Object{
Get-RegString -Key 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\powerchute network Shutdown' -Value UninstallString
}
Reply To: Injecting multiple lines of text into a file
That did it, thanks!
Reply To: Uninstall Sofware using registry key
Hey Marc,
If I understand right, you're wanting to do remote uninstalls?
In case you might come across some systems that do not have the software installed, or have for whatever reason a slightly different uninstall cmd, it's probably best to do the reading of the registry key within the remote scriptblock. Based on whether or not you get a result from trying to read this key, you can then carry out the rest of the script for uninstalling.
Here's a rough guide to the type of thing I think you'd need to do. The cmd /c $uninstallCMD should allow you to execute the command without the need for parsing the arguments. Bear in mind that when you run this, the remote session will be frozen until the uninstallation ends. I've not checked the code entirely, so you may need to do a couple of changes.
Get-QADComputer -Searchroot 'OU=Servers,DC=DOMAIN,DC=ca'| ForEach-Object -Process { [PSCustomObject] @{ Servername = $_.name online = Test-Connection -ComputerName $_.name -Count 1 -Quiet } } | Export-Csv -Path c:\Results.csv -NoTypeInformation $Results = Import-Csv -Path c:\Results.csv | Where-Object -FilterScript { $_.name -eq 'online' } #Let's start doing the remote uninstalls ForEach ($computername in $Results.servername) { Invoke-Command -ComputerName $computername -ScriptBlock { $ErrorAction = 'Stop' Try { $UninstallCMD = Get-RegString -Key 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\powerchute network Shutdown' -Value UninstallString } Catch { } If ($UninstallCMD) { cmd.exe /c $UninstallCMD } } }
Reply To: Dynamic resouce list possible to create Azure VMs?
Offhand, I don't think it "likes" dynamic resource names – I don't think the logic supports that. I'd have to dig into the script module to confirm, though.
But… I'm not positive you need to do all this. The MOF that's produced as the result of the configuration script doesn't contain the computer name. The only reason you input a computer name to the configuration script, basically, is to establish the filename. I'm off the top of my head here, and I may be mixing v4 and v5, but there shouldn't be anything wrong in producing one MOF and just sending it to multiple machines, if that's what you're doing.
Or is it that you're trying to feed in variable data for each machine, and produce what amounts to a unique MOF per host? Keep in mind you don't HAVE to write a configuration script. You only need a MOF. If you're not getting the flexibility you need from the configuration language, you could produce the MOF in other ways.
Reply To: N+1 configuration with 4 Physical Blades assigned to a single resource pool
I'm not entirely sure of the question – are you really asking "how do I query the total number of time in the cluster?"
Not to just pass you off, but if you're not getting a good answer here, my understanding is that the official PowerCLI forums are a good place for questions on that topic.