PowerShell ISE
12 TopicsHow 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, BrahmaSolved20KViews0likes5CommentsPowerShell 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.5KViews1like4CommentsRun 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?4.1KViews0likes5CommentsHow 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.7KViews1like1CommentCannot 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.6KViews0likes0CommentsHybrid Exchange/O365 Automation (Off boarding)
I have been working with a script that was handed off to me. Its purpose was to automate some of our off-boarding processes on our Hybrid Exchange/Microsoft O365 server. It's worked in the past, but has been slowly breaking as time has moved on. Currently, my biggest challenge is trying to figure out why it won't let myself and a few other admins connect to our exchange/O365 server. I have a sneaking suspicion it's related to the currently installed modules/available cmdlets. The following modules are what is currently installed on my work machine; Version Name Repository Description ------- ---- ---------- ----------- 2.0.2.135 AzureAD PSGallery Azure Active Directory V2 General Availability Module.... 2.0.5 ExchangeOnlineManagement PSGallery This is a General Availability (GA) release of Exchange Online PowerShell V2 module.... 1.1.183.57 MSOnline PSGallery Microsoft Azure Active Directory Module for Windows PowerShell 1.4.7 PackageManagement PSGallery PackageManagement (a.k.a. OneGet) is a new way to discover and install software packages from around the web.... 2.2.5 PowerShellGet PSGallery PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Mod... ------------------------------------ I'm currently using; $Credentials = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session ------------------------------------- Which presents this error: New-ExoPSSession : unknown_user_type: Unknown User Type At C:\users\jbarckley\AppData\Local\Apps\2.0\RRGW2CXO.DNX\4YNQ6P50.D87\micr..tion_1f16bd4ec4c2bb19_0010.0000_673f37c317fb5976\CreateExoPSSession.ps1:302 char:30 + ... PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName.Va ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AdalException + FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession ----------------------------------------------------------------------------------------------------- New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : For more information, see the about_Remote_Troubleshooting Help topic. At line:2 char:12 + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : -2144108477,PSSessionOpenFailed Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again. At line:3 char:18 + Import-PSSession $Session + ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand ---------------------------------------------------------------- Do these cmdlets only work in the EXO v1 Module? Any advice would be great!1.8KViews0likes1CommentWindows Servers Uptime Report using PowerShell
Hi Folks, A customer has mix of Windows servers (2012, 2016, 2019) on-premises environment. Customer needs to generate a report via PowerShell about the availability of servers. During my search I found a script on this link and its modified version is attached. Please note, this script reads windows events and based on that produces result. There is a problem where I need help, this script doesn't run against list of servers via a CSV file or a text file and we suspect it is not producing correct result. Can somebody please review this script and help us with the right syntax or what is missing here? Thanks in advance.1.4KViews0likes1CommentScript 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.4KViews0likes1CommentAssistant 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!968Views0likes1Comment