Quantcast
Channel: PowerShell.org » All Posts
Viewing all 13067 articles
Browse latest View live

Reply To: Install Software from network path using Package

$
0
0

Well, I suspect that using File or xRemoteFile would result in more overall network usage, but I can't say by exactly how much. They cache the file localy, but that cache is wiped out every time you apply a new configuration. Package, on the other hand, doesn't download a local copy of the msi at all when you use a UNC path. (This may be the cause of the slowness / hang, though; maybe it _should_ cache a local copy of the file under these circumstances, instead of trying to do everything over the network.)

The main advantage of using Package without File/xRemoteFile (assuming it works) would be that it doesn't need to download the file at all until it calls Set-TargetResource.


BITS Transfer with GUI Progress Bar

$
0
0

So I'd like to first thank anyone who can help out with my problem although it's not entirely mission critical, it is interesting to figure out, and I'd like some help refactoring this code.
The problem is regarding BITS transfers. BITS is an amazing service and for anyone doing local network transfers it's tits and you need to start using it. Here's a great example of how you can use BITS to store a background job transferring multiple files through the network, and if an error occurs, automatically restart the job:

get-module bitstransfer
Start-BitsTransfer -Destination \\pathto\transfer -Source d:\files*.* -Asynchronous -Credential (Get-Credential) -Priority  -RetryTimeout 60 -RetryInterval 120
 
$bits = Get-BitsTransfer -Name "BITS Transfer"
 
while ($bits.JobState -eq "Transferring" -or $bits.JobState -eq "TransientError" -or $bits.JobState -eq "Connecting" -or $bits.jobstate -eq "Error"  -and $pct -ne 100){
    if ($bits.jobstate -eq "Error"){
        Resume-BitsTransfer -BitsJob $bits
    }
 
    $pct = ($bits.BytesTransferred / $bits.BytesTotal)*100
    Write-Host "Percent complete: $pct" 
    Start-Sleep 5
}

As you can see, it also updates you with the percent transferred. It's rough around the edges but it works. While you could just substitute that with write-progress, you could actually add a GUI progress bar and be all spiffy with a gui tool (script repurposed from http://mcpmag.com/articles/2014/02/18/progress-bar-to-a-graphical-status-box.aspx ):

Add-Type -assembly System.Windows.Forms
 
#title for the winform
$Title = "BITS Transfer Progress"
#winform dimensions
$height=100
$width=400
#winform background color
$color = "White"
 
#create the form
$form1 = New-Object System.Windows.Forms.Form
$form1.Text = $title
$form1.Height = $height
$form1.Width = $width
$form1.BackColor = $color
 
$form1.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle 
#display center screen
$form1.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
 
# create label
$label1 = New-Object system.Windows.Forms.Label
$label1.Text = "not started"
$label1.Left=5
$label1.Top= 10
$label1.Width= $width – 20
#adjusted height to accommodate progress bar
$label1.Height=15
$label1.Font= "Verdana"
#optional to show border 
#$label1.BorderStyle=1
 
#add the label to the form
$form1.controls.add($label1)
 
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$progressBar1.Name = 'progressBar1'
$progressBar1.Value = 0
$progressBar1.Style="Continuous"
 
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = $width – 40
$System_Drawing_Size.Height = 20
$progressBar1.Size = $System_Drawing_Size
 
$progressBar1.Left = 5
$progressBar1.Top = 40
$form1.Controls.Add($progressBar1)
$form1.Show()| out-null
 
#give the form focus
$form1.Focus() | out-null
 
#update the form
$label1.Text = "Preparing to send files"
$form1.Refresh()
 
start-sleep -Seconds 1
 
get-module bitstransfer
Start-BitsTransfer -Destination \\pathto\transfer\ -Source d:\file*.* -Asynchronous -Credential (Get-Credential) -Priority Normal -RetryTimeout 60 -RetryInterval 120 -DisplayName "AutoTransfer" -Description "GUI Test"
 
$bits = Get-BitsTransfer -Name "AutoTransfer"
$pct = 0
while ($bits.JobState -ne "Transferred"  -and $pct -ne 100){
    if ($bits.jobstate -eq "Error" -or $bits.JobState -eq "TransientError" ){
        Resume-BitsTransfer -BitsJob $bits
    }
 
    $pct = ($bits.BytesTransferred / $bits.BytesTotal)*100
    $progressbar1.Value = $pct
    Start-Sleep -Milliseconds 100
    $label1.text="Sending files…"
    $form1.Refresh()
}
 
$form1.Close()

As a proof of concept, I was pretty impressed. But here's where I hit a wall. I tried to integrate it into a script of my own but I can't seem to get the BITS transfer to run as a background task.
The problem is that as soon I integrate the task into a function, the BITS transfer doesn't seem to play nice with the rest of the progress bar logic. I have the problem script attached as a file. It's a large script but it's mostly because of the gui elements. The problem lies in the functions set-progress and copy-cpslist I think. In debugging the script, I found that what happens is that the BITS transfer job starts and completes before the while loop begins. Even when using start-job the same issue arises. I'm pretty sure that BITS runs in the foreground because it's being called inside a function. However, I'd rather not presume and find out for sure. It would be very interesting to know what's going on in the background. Thanks ahead of time.

Attachments:
You must be logged in to view attached files.

Reply To: Getting SmartCard Credentials

$
0
0

So now I say DOH!! Thanks for the quick response… Don't know why I did not just do it!

Reply To: Remoting with CredSSP to non-trust domain

$
0
0

Thanks Dave:

oh. frustrating. I had it set with:
WSMAN/*.lab.testing.com

and it wasn't working,

I set it to:
WSMAN/*

and now it works.

WTH! Why doesn't the wildcard work? For the -computername argument, I'm always using the FQDN.

Using xNetworking on Server 2008 R2

$
0
0

I posted this on the Q&A for the module, but figured I'd ask here just in case someone already has a workaround…

I'm trying to use the xNetworking module to set Firewall rules on Windows 2008 R2 but keep getting this error: The term 'Get-NetFirewallRule' is not recognized as the name of a cmdlet, function, script file, or operable program. From what I can see, the Get-NetFirewallRule cmdlet isn't available until Win8/2012, so I'm guessing I need to work something out with NETSH.

Reply To: Using xNetworking on Server 2008 R2

$
0
0

That resource does rely on commands introduced in Win2012. You'd have to rewrite the resource to use something older.

Restarting Script

$
0
0

Hello all,

I have a new script I'm working on, and I have it working pretty good until the end. I have a menu that allows the user to run a task, and after it runs it, I want to ask the user if they want to run another task or not. If they don't, I just want to exit. If they do however, I want to return to where it asks what schedule they want to run.

$caption = "Choose SCCM Schedule";
Write-Host "SCCM Task Scheduler" -Fore Magenta
Write-Host
$machine = Read-Host 'What is the machine name?'
Write-Host
$SMSCli = [wmiclass] "\\$machine\root\ccm:SMS_Client"
[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 ){
Write-host "1. Hardware Inventory" -fore Cyan
Write-host "2. Software Inventory" -fore Cyan
Write-host "3. Discovery Data" -fore Cyan
Write-Host
[Int]$xMenuChoiceA = read-host "Select Task to Schedule"}
Switch( $xMenuChoiceA ){
  1{$SMSCli.TriggerSchedule("{00000000-0000-0000-0000-000000000001}"), "Scheduling Hardware Inventory"; break}
  2{$SMSCli.TriggerSchedule("{00000000-0000-0000-0000-000000000002}"), "Scheduling Software Inventory"; break}
  3{$SMSCli.TriggerSchedule("{00000000-0000-0000-0000-000000000003}"), "Scheduling Discovery Data"; break}
}
Write-Host
$message = Write-Host "Do you want to schedule another task?" -foregroundcolor Red
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" 
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0) 
switch ($result)
{
        0 {"You Chose Yes"}
        1 {"You Chose No"}
}

Basically, if they pick yes, I want it tor return to the block that has

[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 ){
Write-host "1. Hardware Inventory" -fore Cyan
Write-host "2. Software Inventory" -fore Cyan
Write-host "3. Discovery Data" -fore Cyan
Write-Host
[Int]$xMenuChoiceA = read-host "Select Task to Schedule"}

Add-PswaAuthorizationRule Syntax

$
0
0

Hi

Im trying to add an 'Add-PswaAuthorizationRule' all the examples in get-help seem to be for users and not user groups?

I have a domain security Group called PowerShellAdmins, I want to grant access to domain computers, and I don't want any restrictions, Ie 'ConfigurationName *'

I HAVE VERY LITTLE POWERSHELL EXP so Im guessing my user group and computer group naming is wrong?

-UserGroupName petenetlive\PowerShellAdmins it does not like
-UserGroupName PowerShellAdmins it does not like

-ComputerGroupName "Domain Computers" it does not like
-ComputerGroupName "petenetlive\Domain Computers" it does not like

Does anyone have an example of this commandlet use for a domain security group – and granting access to a domain computer group (with a space in it name'.

I appreciate this is a massive Noob question – but I've sat in one lecture and watched 3 powershell videos (bear with me.)

Pete


Reply To: Restarting Script

$
0
0

just made a small adjustment :)…see if this works for you..


$caption = "Choose SCCM Schedule";
Write-Host "SCCM Task Scheduler" -Fore Magenta
Write-Host
$machine = Read-Host 'What is the machine name?'
Write-Host
$SMSCli = [wmiclass] "\\$machine\root\ccm:SMS_Client"
[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 3 )
{
Write-host "1. Hardware Inventory" -fore Cyan
Write-host "2. Software Inventory" -fore Cyan
Write-host "3. Discovery Data" -fore Cyan
Write-Host
[Int]$xMenuChoiceA = read-host "Select Task to Schedule"

Switch( $xMenuChoiceA )
{
1{"Scheduling Hardware Inventory"; break}
2{"Scheduling Software Inventory"; break}
3{"Scheduling Discovery Data"; break}
}
Write-Host
$message = Write-Host "Do you want to schedule another task?" -foregroundcolor Red
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result)
{
0 {$xMenuChoiceA = 0}
1 {"You Chose No"}
}

}

Reply To: The Next Scripting Games: Your Thoughts?

$
0
0

I am just beginning my journey in learning Powershell and came across the Powershell.org site which led me to reading about the Scripting Games… so please forgive me if this is already being done since I haven't participated in this before. I was reading what Don posted about what is possible and not possible and what has been asked by others in the past. It sounded like having the judges provide personal feedback was a big thing but because of time and number of entries this wouldn't be possible which makes sense. I was wondering if that could be flipped around? Could the judges submit what they would have done for that particular challenge which would provide insight into what that judge is looking for in an entry as well as educate those of us that are beginning and trying to figure out what the difference would be between a mediocre script and a really good one. In this method, the judges would only have to do one entry rather than comment on multiple entries.

Reply To: Omha user group?

$
0
0

Hi David!
We've been a little behind on updating PowerShell.org when our user group meetings are coming up as well as after meeting notes. We will try to work better on that in the future. You can feel free to follow the twitter account for the user group here: https://twitter.com/OmahaPSUG as we keep folks updated on what is going on with meetings and such.

Reply To: query ad for users sam only & managers sam only?

$
0
0

Thx! Do I have to include the "Display Name" or can I query for only the sAMAccountName of the users and the sAMAccountName of the managers for each user?

Reply To: query ad for users sam only & managers sam only?

$
0
0

Thx! Do I have to include the "Display Name" or can I query for only the sAMAccountName of the users and the sAMAccountName of the managers for each user?

Reply To: query ad for users sam only & managers sam only?

$
0
0

You can exclude the Display Name attribute.

You might also need to add -NoTypeInformation to your Export-CSV command, so that it can be identified when opened in programs such as Excel.

Reply To: Add-PswaAuthorizationRule Syntax

$
0
0

Not one reply :(

I worked it out put domain computers in a security group

Add-PswaAuthorizationRule -ComputerGroupName "petenetlive\PSComputers" -UserGroupName "petenetlive\PSAdmins" -ConfigurationName *

PL


Reply To: Install Software from network path using Package

$
0
0

Hi Dave,

My Bad that the image didn't sync with my question. First, I am trying to install SQLSysClrTyps.msi. So, When I am giving no argument in package error comes as :

PowerShell provider MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: The return code 1619 was not expected. Configuration is likely not correct

If I provide the arguments looking into some powershell blogs , the installation gets stuck. PFA screenshot.

Thanks,
Aravinda

Attachments:
You must be logged in to view attached files.

Reply To: Restarting Script

$
0
0

This worked perfectly, thank you!

Reply To: Install Software from network path using Package

$
0
0

Return code 1619 is this: "This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package."

I'm not sure where you found those arguments; they look more appropriate for an exe wrapper around an MSI, rather than for an MSI directly. This might work, if those arguments are for this particular package, though:

Arguments = '/qn ALLUSERS=1 REBOOT=ReallySuppress'

Reply To: Install Software from network path using Package

$
0
0

HI Dave,

The issue is same after changing the Arguments also. PFA.
Using xRemoteFile we can download one software from a URI, but what is the method to copy a fiel from a network path/

Thanks,
Aravinda

Attachments:
You must be logged in to view attached files.

Reply To: Install Software from network path using Package

$
0
0

For UNC, you'd probably just use File.

Viewing all 13067 articles
Browse latest View live