PowerShell ISE
10 TopicsHow to use output from 1 script in another script ??
I am trying to take the output from Script 1 and execute the actions in Script 2 against it. Script 1 = Select Device from a drop down list Script 2 = Execute option 1 or 2 against the selected Device They both work indendently but I can't figure out how to intergrate the two. Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $form = New-Object System.Windows.Forms.Form $form.Text = 'Select a Computer' $form.Size = New-Object System.Drawing.Size(300,200) $form.StartPosition = 'CenterScreen' $okButton = New-Object System.Windows.Forms.Button $okButton.Location = New-Object System.Drawing.Point(75,120) $okButton.Size = New-Object System.Drawing.Size(75,23) $okButton.Text = 'OK' $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.AcceptButton = $okButton $form.Controls.Add($okButton) $cancelButton = New-Object System.Windows.Forms.Button $cancelButton.Location = New-Object System.Drawing.Point(150,120) $cancelButton.Size = New-Object System.Drawing.Size(75,23) $cancelButton.Text = 'Cancel' $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.CancelButton = $cancelButton $form.Controls.Add($cancelButton) $label = New-Object System.Windows.Forms.Label $label.Location = New-Object System.Drawing.Point(10,20) $label.Size = New-Object System.Drawing.Size(280,20) $label.Text = 'Please select a computer:' $form.Controls.Add($label) $listBox = New-Object System.Windows.Forms.ListBox $listBox.Location = New-Object System.Drawing.Point(10,40) $listBox.Size = New-Object System.Drawing.Size(260,20) $listBox.Height = 80 [void] $listBox.Items.Add(‘ORTECLAB001’) [void] $listBox.Items.Add('ORTECLAB002’) [void] $listBox.Items.Add('ORTECLAB003’) [void] $listBox.Items.Add('ORTECLAB004’) [void] $listBox.Items.Add('ORTECLAB005') [void] $listBox.Items.Add('ORTECLAB006') [void] $listBox.Items.Add('ORTECLAB007') [void] $listBox.Items.Add('ORTECLAB008') [void] $listBox.Items.Add('ORTECLAB009') [void] $listBox.Items.Add('ORTECLAB010') [void] $listBox.Items.Add('ORTECLAB011') [void] $listBox.Items.Add('ORTECLAB012') [void] $listBox.Items.Add('ORTECLAB013') [void] $listBox.Items.Add('ORTEC00348') $form.Controls.Add($listBox) $form.Topmost = $true $result = $form.ShowDialog() if ($result -eq [System.Windows.Forms.DialogResult]::OK) { $x = \\10.X.X.253\c$\Users\smorgan\Documents\Shutdown.ps1 $x } [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $x=args[0] $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Shutdown | Restart" $objForm.Size = New-Object System.Drawing.Size(300,300) $objForm.StartPosition = "CenterScreen" $objForm.FormBorderStyle = "FixedSingle" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(205,220) $CancelButton.Size = New-Object System.Drawing.Size(75,25) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $SButton = New-Object System.Windows.Forms.Button $SButton.Location = New-Object System.Drawing.Size(15,220) $SButton.Size = New-Object System.Drawing.Size(75,25) $SButton.Text = "Shutdown" $SButton.Add_Click({Stop-Computer -Force}) $objForm.Controls.Add($SButton) $RButton = New-Object System.Windows.Forms.Button $RButton.Location = New-Object System.Drawing.Size(110,220) $RButton.Size = New-Object System.Drawing.Size(75,25) $RButton.Text = "Restart" $RButton.Add_Click({Restart-Computer -Force}) $objForm.Controls.Add($RButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,20) $objLabel.Size = New-Object System.Drawing.Size(280,120) $objLabel.Text = "Please ensure you have selected the correct LAC/E Box before proceeding." $objForm.Controls.Add($objLabel) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog()2.6KViews1like1CommentRun Script from SCCM
I am a novice at PowerShell. I have a request to run a script from SCCM to install a list of printer drivers. Script is as follows... # Ricoh Universal Print Driver Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\Universal Print Driver ver4_27\disk1" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } # Ricoh SP3410dn Print Driver Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP 3410DN\PCL6\DISK1" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } # Ricoh SP3510dn Print Driver Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP 3510DN\PCL6\DISK1" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } # Ricoh SPC232dn Print Driver Get-ChildItem "\\server\d$\Print_Drivers\Ricoh\SP C232DN\PCL6\DISK1" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } # HP T1300 Print Driver Get-ChildItem "\\server\d$\Print_Drivers\HP\T1300 PS Server 2016\win_x64_ps3_drv\win_x64_ps3_drv" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } # Zebra ZDesigner GX420t Print Driver Get-ChildItem "\\server\d$\Print_Drivers\Other\Zebra\ZD5-1-16-7110\ZBRN" -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } I can run this script locally on a machine & it runs fine, takes about 90 seconds to complete. When I create an application for it in SCCM & deploy it, its like it doesn't have time to complete the installs before PowerShell shuts down. Then the app shows as failed in Software Center. How do I make it wait to finish running the script before closing out PowerShell?3.9KViews0likes5CommentsHow to run Powershell command in Loop
Hi, I am new to Powershell script and Need your help on below requirement. I am have powershell script displaying last last 3 commands and output of my powershell script. Below last 3 command lines: $FinalResource=$FinalResource1 | Where-Object{$_.ResourceType -ne $MetricType} Write-Output $FinalResource New-AzResourceLock -LockLevel CanNotDelete -LockName Delete_Lock -ResourceName $FinalResource.Name -ResourceType $FinalResource.ResourceType -ResourceGroupName xxxxxx Below is Output of my powershell script: I am getting list of resources which are not having LOCKS on Azure after that I am applying lock on each resource by using above command. Script is running fine when I am passing single resource but script is failing when I am passing all resources. How to run last command in loop by passing one by one resource so that lock command will apply on all resources. Thanks, BrahmaSolved20KViews0likes5CommentsScript to know Access on User/Group Account
Hi Team, Is there a way to get a list of servers that user or a group has access? I am looking for a script that would give me list of servers in which that particular user or group is added to Server Local Administrators. Thanks Yash1.3KViews0likes1CommentHow to migrate selected folder and files permission from OneDrive to Sharepoint Online?
We are migrating all the permission of selected contents(files and folders) from the OneDrive to SharePoint Online, if number of files are less than 100, script migrate it's in half an hour, however, if the count of files more than 5000 then it will takes around 10 hours, which is effecting the performance of migration. Kindly find below the portion of code for getting the permissions. #$fileUrl -NewFolder/logo.png $file = Get-PnPFile -Url $fileUrl -AsListItem Get-PnPProperty -ClientObject $file -Property RoleAssignments $members = Get-PnPProperty -ClientObject $roleAssignments -Property RoleDefinitionBindings, Member $member = $roleAssignments.Member #list of users $Users = Get-PnPProperty -ErrorAction SilentlyContinue -ClientObject $member -Property Users #Return Accesstype $accessType = $roleAssignments.RoleDefinitionBindings.Name; Hence, we are decide to use workflow in the PowerShell script, as shown in the below link: https://gist.github.com/jamiekt/f586e47cb96b93dacbe5 But this link doesn't fulfil our requirement. Kindly let us any suitable solution in the PowerShell to meet our requirement879Views0likes0CommentsCannot convert the "Microsoft.SharePoint.Client.ListItem" value of type "Microsoft.SharePoint.Clien
When we run the below script on the Power shell version 5.1 for fetching file property. workflow IterateWorkflow { Parallel { Connect-PnPOnline -Url $SrcFolderURL -Credentials $creds -ErrorAction SilentlyContinue -WarningAction SilentlyContinue $folderUrl = "/Documents/It's a level 3 folder for testing/Level 4/file-sample_100kB.doc" $file = Get-PnPFile -Url $folderUrl -AsListItem if ($file) { Get-PnPProperty -ClientObject $file -Property HasUniqueRoleAssignments, RoleAssignments } else { $file = Get-PnPFile -Url $folderUrl -AsListItem Get-PnPProperty -ClientObject $file -Property HasUniqueRoleAssignments, RoleAssignments } } } We are getting Microsoft related issue, however, its running successful on non-workflow the Power Shell. Cannot bind parameter 'ClientObject'. Cannot convert the "Microsoft.SharePoint.Client.ListItem" value of type "Deserialized.Microsoft.SharePoint.Client.ListItem" to type "Microsoft.SharePoint.Client.ClientObject"2.5KViews0likes0CommentsPowerShell ISE is a blank white on black Window after update to Windows 10 Version 1903
Powershell ISE is not working on my Windows 10 laptop, not sure when this happened but i am just updated to Version 1903. Does anyone know how to fix this problem, I have attached an image showing how the ISE looks, see below. This is very annoying, Help! B6.3KViews1like4CommentsAssistant creating array?
Hi, I'm a Powershell Amateur! I've written some code to import data from logfile.txt and export the results with export-csv to a weapons_date. I'm replicating each line but I'm sure I might be able to do this better, perhaps with an array or loop or something? I did some basic research but don't fully understand arrays Clear-Host $TestPath = $null $sourcefile = "logfile.txt" $dest = "weapons_" $date = (Get-Date -Format "%d%M%y-%H%m%s") $target = $dest+$date+".csv" if (Test-Path $destinationfile) {Remove-Item $destinationfile} Get-Content $sourcefile | Select-String -Pattern "weapon_sks" | Measure-Object -Line | Add-Member -MemberType NoteProperty -Name Weapon -Value SKS -PassThru | Export-Csv -Path $target -NoTypeInformation Get-Content $sourcefile | Select-String -Pattern "weapon_rpk" | Measure-Object -Line | Add-Member -MemberType NoteProperty -Name Weapon -Value RPK -PassThru | Export-Csv -Path $target -NoTypeInformation -Append [System.Windows.MessageBox]::Show('Parsing Log File complete','Logfile Outcome','OK') Hoping to build array to make file much shorter so I can perhaps just read from a string or csv with list of names? Cheers!947Views0likes1Comment