Some More Primal Forms tidbits


This is just a reminder for me about how to do some things with Primal Forms.
1. Include a Snapin
2. Add a new line to the $richTextbox


function OnApplicationLoad {
	#Note: This function is not called in Projects
	#Note: This function runs before the form is created
	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
	#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
	#Important: Form controls cannot be accessed in this function
	#TODO: Add snapins and custom code to validate the application load
	$q = get-pssnapin Quest* -ea "silentlycontinue"
	If ($q.name -ne "Quest.ActiveRoles.ADManagement") {
	Add-PSSnapin Quest.ActiveRoles.ADManagement }
	return $true #return true for success or false for failure
}

function OnApplicationExit {
	#Note: This function is not called in Projects
	#Note: This function runs after the form is closed
	#TODO: Add custom code to clean up and unload snapins when the application exits
	
	$script:ExitCode = 0 #Set the exit code for the Packager
}

$formGetQAUsersGroups_Load={
	#TODO: Initialize Form Controls here
	
}

$butonRun = {
	$a = Get-QADMemberOf $UserBox.Text 
	foreach ($item in $a) { $item.Name | Out-File c:\useroutput.txt -Append}
	$richtextbox1.text = [string]::join([environment]::newline, (Get-Content c:\useroutput.txt))
	del c:\useroutput.txt
}

$BtnExit_Click = {
$formGetQAUsersGroups.Close()	
}

Advertisements

Link

How can I tell if there is a reboot pending on a Windows 2008 R2 server?

I found my answers here:
techmumbojumblog.com


###### Start Posh Script ########

function Get-PendingReboot($computer = '.') {
	$hkey		= 'LocalMachine';
	$path_server	= 'SOFTWARE\Microsoft\ServerManager';
	$path_control	= 'SYSTEM\CurrentControlSet\Control';
	$path_session	= join-path $path_control 'Session Manager';
	$path_name	= join-path $path_control 'ComputerName';
	$path_name_old	= join-path $path_name 'ActiveComputerName';
	$path_name_new	= join-path $path_name 'ComputerName';
	$path_wsus = 'SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired';
	$pending_rename	= 'PendingFileRenameOperations';
	$pending_rename_2	= 'PendingFileRenameOperations2';
	$attempts	= 'CurrentRebootAttempts';
	$computer_name	= 'ComputerName';

	$num_attempts	= 0;
	$name_old	= $null;
	$name_new	= $null;

	$reg= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $computer);

	$key_session	= $reg.OpenSubKey($path_session);
	if ($key_session -ne $null) {
		$session_values	= @($key_session.GetValueNames());
		$key_session.Close() | out-null;
	}

	$key_server	= $reg.OpenSubKey($path_server);
	if ($key_server -ne $null) {
		$num_attempts = $key_server.GetValue($attempts);
		$key_server.Close() | out-null;
	}

	$key_name_old	= $reg.OpenSubKey($path_name_old);
	if ($key_name_old -ne $null) {
		$name_old = $key_name_old.GetValue($computer_name);
		$key_name_old.Close() | out-null;

		$key_name_new	= $reg.OpenSubKey($path_name_new);
		if ($key_name_new -ne $null) {
			$name_new = $key_name_new.GetValue($computer_name);
			$key_name_new.Close() | out-null;
		}
	}
	
		$key_wsus = $reg.OpenSubKey($path_wsus);
		if ($key_wsus -ne $null) {
		$wsus_values = @($key_wsus.GetValueNames());
		if ($wsus_values) {
		$wsus_rbpending = $true
		} else {
		$wsus_rbpending = $false
		}
		$key_wsus.Close() | out-null;
		}

	$reg.Close() | out-null;
	#modified return section:	
		if ( `
		(($session_values -contains $pending_rename) -or ($session_values -contains $pending_rename_2)) `
		-or (($num_attempts -gt 0) -or ($name_old -ne $name_new)) `
		-or ($wsus_rbpending)) {
		return $true;
		}
		else {
		return $false;
		}
}