Reply To: Help deciphering powershell code
Ah, the old “a cat walked across my keyboard” approach to software development. Poshoholic’s version is better, though in production code I wouldn’t even bother with the comments. It’s pretty...
View ArticleReply To: Help deciphering powershell code
For the record, the comments were added for the forum reader. I wouldn’t put those comments in my scripts either, unless it was some particularly obscure piece of logic that I wanted to explain or some...
View ArticleReply To: Null-valued expression after starting RemoteRegistry service
Thanks, Dave! That seems to work, but I’m still not sure I understand why. I’ll have to look at this one for a while… I appreciate the help, though!
View ArticleRegistry key issue
Ok, so I am attempting to get a programs version number by accessing the registry key that holds it.Here is my code:Function StartRemRegSvc {(get-wmiobject -computer $strcomputer win32_service -filter...
View ArticleReply To: Null-valued expression after starting RemoteRegistry service
Here’s a stripped-down version of your original code which will hopefully make the problem more clear: function ExampleFunction { $reg = $null try { $reg = SomeMethodWhichMayThrowAnException } catch...
View ArticleReply To: Registry key issue
First, I assume you are using the Powershell Remote Registry from http://psrr.codeplex.com/wikipage?title=Get-RegValue. I downloaded it and it looks like they are calling a .NET method to do the remote...
View ArticleIf Statement Help
I created a script to copy groups from templates user names we have in a flat file on a network share. The script works good, however I’m having an issue with the If statements that give a status. I...
View ArticleReply To: If Statement Help
I’m not sure what you’re asking, since you’ve removed the If statement that was giving you problems. Are you just trying to detect whether the user has entered any text? If so, you have a couple of...
View ArticleReply To: If Statement Help
Good call! The if ($DName.TextLength -eq 0) { } worked perfectly. I was initially trying if ($DName.Text -eq $null) which wasn’t working.
View ArticleReply To: If Statement Help
In this case, it’s never null. If the box is empty, the Text property will return a non-null (but empty) string.In general, you can avoid having problems with this distinction by using the...
View ArticleReply To: If Statement Help
Dave Wyatt wrote:can avoid having problems with this distinction by using the String.IsNullOrEmpty method:if ([String]::IsNullOrEmpty($someVariable)) { }Thanks for the feedback. I appreciate the help.
View ArticleSecure string vs. encrypted standard string
Can someone help me in understanding the difference between a secure string and an encrypted standard string?From the PowerShell help: “The ConvertFrom-SecureString cmdlet converts a secure string...
View ArticleReply To: Null-valued expression after starting RemoteRegistry service
No problem! If you wanted to, you could have implemented this without recursion (personal preference there. Sometimes one is better than the other, sometimes it just doesn’t matter). Here’s an example...
View ArticleReply To: Secure string vs. encrypted standard string
Export-CliXml will do the conversion for you. ConvertFrom-SecureString is mainly if you want to write your own file output (via Add-Content, Out-File, or whatever).
View ArticleReply To: Registry key issue
Thanks, I was guessing that the braces are the issue because that key is definitely there. And yes I am using the PS Remote Registry module. I tested with the double brackets and am continuing to get...
View ArticleReply To: Registry key issue
It’s probably nothing, but have you tried using single quotes instead of double quotes when using Get-RegValue. For example:get-regvalue -computername $strcomputer -key...
View ArticleReply To: Registry key issue
I’ve never used that particular module before, and would have to step through the code in a test environment to try to find the problem.You have a dependency on WMI in your code anyway (to start the...
View Articlemashing scripts
This script allows me to display a lst of security groups in an OU`Get-ADGroup -Filter {GroupCategory -eq 'Security'} -searchbase 'My OU Here' `This script allows me to use an input file containing...
View ArticleReply To: mashing scripts
Please use the CODE button in the toolbar to format code. Works a lot betterer.Start by putting the groups you want into a variable: $groups = Get-ADGroup -Filter {GroupCategory -eq 'Security'}...
View Article